In GalleryView, we want to be able to select favorites that we can show in MainView. To do that, we need to store the photos that we have selected so that it remembers our selection. Create a new interface in the GalleryApp project named ILocalStorage:
public interface ILocalStorage
{
Task Store(string filename);
Task<List<string>> Get();
}
The easiest way to store/persist data in Xamarin.Forms is to use the built-in property store. Properties is a property of the Application class, the base class of our App class. Follow these steps to use it:
- Install the Newtonsoft.Json NuGet package for the GalleryApp project.
- Create a new class named FormsLocalStorage in the GalleryApp project.
- Implement the ILocalStorage interface:
public class FormsLocalStorage : ILocalStorage
{
public const string FavoritePhotosKey = "FavoritePhotos";
public async Task<List<string>> Get()
{
if (Application.Current...