Неизвестный список студентов (1-99?). В каждой карточке студента есть индикатор выполнения (если применимо). Обновление на временной интервал. (Количество учеников может меняться в зависимости от данных, времени дня и т. д. c, но не обновляется столько же, сколько индикатор выполнения)
На android все работает нормально, с интервалом обновляется viewModel и если есть изменение, индикатор выполнения меняется ... на iOS он обновляет всю страницу (что раздражает, если вы прокрутите вниз, чтобы проверить определенного c студента и должны продолжать это делать)
Можно ли получить тот же результат на iOS?
Вот фрагмент кода TodayPage.xaml
<DataTemplate x:Key="runTemplate">
<ViewCell>
<Grid> ....
<DataTemplate x:Key="studentTemplate">
<ViewCell>
<Grid> ...
<ProgressBar Grid.Row="0" Grid.ColumnSpan="6" x:Name="pb_TodayRun" Margin="0,0" Progress="{Binding progress}" ProgressColor="{StaticResource Secondary}" IsVisible="{Binding displayPB}"></ProgressBar>
<toolkit:TodayDataTemplateSelector x:Key="todayDataTemplateSelector"
RunTemplate="{StaticResource runTemplate}"
StudentTemplate="{StaticResource studentTemplate}"
TopTemplate="{StaticResource topTemplate}" />
Некоторые из кода позади:
public partial class TodayPage : ContentPage
{
TodayViewModel viewModel;
private bool isShown = true;
public TodayPage()
{
InitializeComponent();
BindingContext = viewModel = AppContainer.Resolve<TodayViewModel>();
}
protected override void OnAppearing()
{
base.OnAppearing();
UpdateProgress(true);
isShown = true;
Device.StartTimer(TimeSpan.FromSeconds(60/*viewModel.AutoRefreshTime*/), () =>
{
if (isShown)
{
UpdateProgress(false);
return true;
}
else
return false;
});
}
protected override void OnDisappearing()
{
base.OnDisappearing();
isShown = false;
}
public async void UpdateProgress(bool allowCached)
{
await viewModel.LoadItems(allowCached);
}
и TodayViewModel.cs
public class TodayViewModel : BaseViewModel , INotifyPropertyChanged
{
private readonly IStudentService _studentService;
private readonly ISettingsService _settingsService;
public ObservableCollection<TodayCell> Items { get; set; }
public Command LoadItemsCommand { get; set; }
public int AutoRefreshTime
{
get => _settingsService.AutoRefreshTimeSetting;
}
public TodayViewModel(IConnectionService connectionService, IDialogService dialogService, IStudentService studentService, ISettingsService settingsService)
: base(connectionService, dialogService)
{
_studentService = studentService;
_settingsService = settingsService;
Items = new ObservableCollection<TodayCell>
{
new TodayCell.Top()
};
LoadItemsCommand = new Command(async (Object param) => await ExecuteLoadItemsCommand(param != null && param.Equals(true)));
}
public async Task ExecuteLoadItemsCommand(bool allowCached)
{
if (IsBusy) return;
IsBusy = true;
try
{
await LoadItems(allowCached);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
finally
{
IsBusy = false;
}
}