protected override void OnNavigatedTo(NavigationEventArgs e) { string selectedIndex = ""; if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex)) { int index = int.Parse(selectedIndex); string fromFavoritesFlag = "0"; if (NavigationContext.QueryString.TryGetValue("fromFavorites", out fromFavoritesFlag)) { ourItem = App.ViewModel.ItemsPertanyaanFavorit[index]; } else { ourItem = App.ViewModel.ItemsPertanyaan[index]; } Uri uri2 = new Uri(ourItem.Gambar, UriKind.Relative); ImageSource imgSource2 = new BitmapImage(uri2); gambar.Source = imgSource2; pertanyaanNumber = ourItem.IdPertanyaan; DataContext = ourItem; if (ourItem.IsFavorite) { Uri uri = new Uri("Assets/Images/favorite.png", UriKind.Relative); ImageSource imgSource = new BitmapImage(uri); FavoriteImage.Source = imgSource; } } }
public static ObservableCollection <PertanyaanViewModel> LoadDataBasePertanyaanFromXML() { ObservableCollection <PertanyaanViewModel> items = new ObservableCollection <PertanyaanViewModel>(); XDocument xdoc = XDocument.Load("Content/PertanyaanData.xml"); var dataEnum = xdoc.Descendants("Pertanyaan"); int sonnetNumber = 1; foreach (XElement e in dataEnum) { PertanyaanViewModel ivm = new PertanyaanViewModel(); ivm.JudulPertanyaan = (string)e.Element("Judul").Value; ivm.IntroPertanyaan = (string)e.Element("Number").Value; ivm.Gambar = (string)e.Element("Gambar").Value; int lineNum = 1; string sonnetBody = ""; var bodyEnum = e.Element("Body").Descendants("Line"); foreach (XElement line in bodyEnum) { if (lineNum < 13) { sonnetBody = sonnetBody + "\r\n" + line.Value; } else { sonnetBody = sonnetBody + "\r\n " + line.Value; } lineNum++; } ivm.IsiJawaban = sonnetBody; ivm.IsFavorite = false; ivm.IdPertanyaan = sonnetNumber; items.Add(ivm); sonnetNumber++; } return(items); }