We will start by creating a ViewModel model that we will use for the view. In the ViewModel folder in the GalleryApp project, create a new class named MainViewModel:
public class MainViewModel : ViewModel
{
private readonly IPhotoImporter photoImporter;
private readonly ILocalStorage localStorage;
public ObservableCollection<Photo> Recent { get; set; }
public ObservableCollection<Photo> Favorites { get; set; }
public MainViewModel(IPhotoImporter photoImporter, ILocalStorage localStorage)
{
this.photoImporter = photoImporter;
this.localStorage = localStorage;
}
public async Task Initialize()
{
var photos = await photoImporter.Get(0, 20, Quality.Low);
Recent = photos;
RaisePropertyChanged(nameof(Recent));
await LoadFavorites();
MessagingCenter.Subscribe<GalleryViewModel>(this, "FavoritesAdded", (sender) =>
{
...