To load more than the first 20 items, we will load photos incrementally so that when users scroll to the end of CollectionView, it will start to load more items. CollectionView has built-in support for loading data incrementally. Because we get an ObeservableCollection object back from the photo importer and data is added asynchronously to it, we need to create an event listener to handle when items are added to the photo importer so that we can add it to the ObservableCollection instance that we bound to CollectionView. Create the event listener by following these steps:
- Navigate to GalleryViewModel.cs.
- Add the following code:
private int itemsAdded;
private void Collection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
{
foreach(Photo photo in args.NewItems)
{
itemsAdded++;
Photos.Add(photo);
}
if(itemsAdded == 20)
{
var collection = (ObservableCollection...