protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string selectedId = ""; if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedId)) { _noteId = selectedId; } _note = App.ViewModel.GetNote(_noteId); _category = _note.Category; string selectedCategoryId = ""; if (NavigationContext.QueryString.TryGetValue("selectedCategory", out selectedCategoryId)) { _categoryId = selectedCategoryId; _category = App.ViewModel.GetCategory(selectedCategoryId); _note.Category = _category; } if (_note != null) { DataContext = _note; } if (_category != null) { textCategory.Text = _category.Title; textCategory.IsEnabled = true; } RelatedNotesListBox.ItemsSource = App.ViewModel.AllNotes.OrderBy(t => t.Title); // Determine which linked notes to check foreach (INote note in RelatedNotesListBox.ItemsSource) { if (_selectedNotes == null) { if (_note.LinkedNotes.Where(t => t.Id.Equals(note.Id)).Any()) { RelatedNotesListBox.SelectedItems.Add(note); } } else { if (_selectedNotes.Contains(note)) { RelatedNotesListBox.SelectedItems.Add(note); } } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Find the related Notes from the selected Category string selectedCategoryId = ""; if (NavigationContext.QueryString.TryGetValue("selectedCategory", out selectedCategoryId)) { _categoryId = selectedCategoryId; INoteCategory category = App.ViewModel.GetCategory(selectedCategoryId); DataContext = category; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Check if a category has been selected from the Category chooser page and retrieve it string selectedCategory = ""; if (NavigationContext.QueryString.TryGetValue("selectedCategory", out selectedCategory)) { _category = App.ViewModel.Context.NoteCategories.Where(t => t.Id.Equals(selectedCategory)).First(); } // If there is a cached Note then reuse the values if (_note != null) { textNote.Text = _note.Body; textTitle.Text = _note.Title; } // If there is a selected Category then reuse the values if (_category != null) { textCategory.Text = _category.Title; textCategory.IsEnabled = true; } if (App.ViewModel.Context.Notes.FirstOrDefault() != null) { NoNotesMessage.Visibility = Visibility.Collapsed; // Fill the Related Notes selector and pre-select Notes in the _selectedNotes cache RelatedNotesListBox.ItemsSource = App.ViewModel.Context.Notes.OrderBy(t => t.Title); if (_selectedNotes != null) { foreach (INote note in RelatedNotesListBox.ItemsSource) { if (_selectedNotes.Contains(note)) { RelatedNotesListBox.SelectedItems.Add(note); } } } } }