public ExploreViewModel() { // Make a list of preselected routes RouteInfo filter1 = new RouteInfo { ImageSource = "", Name = "Classic" }; filter1.ArtStyleFilter = new List <ArtStyle> { new ArtStyle("Classic") }; RouteInfo filter2 = new RouteInfo { ImageSource = "", Name = "17th century" }; filter2.TimePeriodFilter = new List <TimePeriod> { new TimePeriod("17th century") }; RouteInfo filter3 = new RouteInfo { ImageSource = "", Name = "ALEKOS TZOMAKAS" }; filter3.ArtistFilter = new List <Artist> { new Artist("ALEKOS TZOMAKAS") }; PreselectedRoutes = new List <RouteInfo> { filter1, filter2, filter3 }; // Make a list of popular exhibits ExhibitBase exhibitBase = ExhibitBase.GetExhibitBase(); PopularExhibits = new List <ExhibitInfo>(); var FavExhibits = exhibitBase.GetFavourites(); int exhibitCount = Math.Min(5, exhibitBase.Exhibits.Count); for (int i = 0; i < exhibitCount; i++) { Exhibit exhibit = exhibitBase.Exhibits[i]; bool isFav = false; if (FavExhibits.Contains(exhibit)) { isFav = true; } PopularExhibits.Add(new ExhibitInfo(exhibit, isFav)); } }
public ExhibitPage(Guid exhibitID) { InitializeComponent(); viewModel = new ExhibitViewModel(); ExhibitBase exhibitBase = ExhibitBase.GetExhibitBase(); var FavExhibits = exhibitBase.GetFavourites(); Exhibit exhibit = exhibitBase.Exhibits.Find((e) => e.ID == exhibitID); viewModel.ImageSource = exhibit.ImageSource; // TODO: Remove other attributes apart from ID from ExhibitID viewModel.ExhibitID = exhibit.ID; viewModel.ExhibitName = exhibit.Name; viewModel.ExhibitDescription = ArtistBase.GetInstance().GetArtistBio(exhibit.Artist.Name); viewModel.IsFavourite = FavExhibits.Contains(exhibit); BindingContext = viewModel; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (s, e) => { // Switch favourite state if (viewModel.IsFavourite) { // Unfavourite item viewModel.IsFavourite = false; exhibitBase.RemoveFavourite(viewModel.ExhibitID); } else { // Favourite item viewModel.IsFavourite = true; exhibitBase.AddFavourite(viewModel.ExhibitID); } // TODO: Do this using data binding image_favourite.Source = viewModel.FavImageSource; }; image_favourite.GestureRecognizers.Add(tapGestureRecognizer); }