publicPeopleSource() { // Creates an example collection. people = new List<Person>();
for (int i = 1; i <= 200; i++) { var p = new Person { Name = "Person " + i }; people.Add(p); } }
publicasync Task<IEnumerable<Person>> GetPagedItemsAsync(int pageIndex, int pageSize) { // Gets items from the collection according to pageIndex and pageSize parameters. var result = (from p in people select p).Skip(pageIndex * pageSize).Take(pageSize);
// Simulates a longer request... await Task.Delay(1000);
return result; } }
// ViewModel.cs public Items { get; privateset; } = new IncrementalLoadingCollection<PeopleSource, Person>();
publicstaticreadonly DependencyProperty LoadMoreItemsCommandProperty = DependencyProperty.Register(nameof(LoadMoreItemsCommand), typeof(ICommand), typeof(IncrementalLoadingBehavior), new PropertyMetadata(null));
public ICommand LoadMoreItemsCommand { get => (ICommand)GetValue(LoadMoreItemsCommandProperty); set => SetValue(LoadMoreItemsCommandProperty, value); }