private async void EditNote_Click(object sender, RoutedEventArgs e) { // The button is only clickable when there's exactly one item selected // (baring race conditions, of course) foreach (var item in uiList.SelectedItems) { var note = item as UserNoteWithTitle; if (note == null) { continue; // should never happen } var edited = await NoteEditor.EditNoteAsync(ControlId, note.BaseNote); if (edited) { // Update the list... for (int i = 0; i < Notes.Count; i++) { if (Notes[i].Id == note.Id) { Notes.RemoveAt(i); Notes.Insert(i, new UserNoteWithTitle(note.BaseNote, note.DisplayTitle)); } } } } }
/// <summary> /// Returns TRUE if a note was edited, FALSE otherwise. /// </summary> /// <param name="controlId"></param> /// <param name="note"></param> /// <returns></returns> public static async Task <bool> EditNoteAsync(NavigateControlId controlId, UserNote note) { var bookdb = BookDataContext.Get(); var edited = false; var cd = new ContentDialog() { Title = "Edit Bookmark (Note)", PrimaryButtonText = "OK", SecondaryButtonText = "Cancel" }; var ne = new NoteEditor(); ne.DataContext = note; cd.Content = ne; var result = await cd.ShowAsync(); switch (result) { case ContentDialogResult.Primary: ne.SaveNoteIfNeeded(controlId, bookdb); edited = true; break; case ContentDialogResult.Secondary: // Cancel means don't save the note. edited = false; break; } return(edited); }
private async void OnAddNote(object sender, RoutedEventArgs e) { var location = GetCurrBookLocation().ToJson(); string currSelection = ""; if (CurrHtml != null && CurrHtml.Contains("DoGetSelection")) { currSelection = await uiHtml.InvokeScriptAsync("DoGetSelection", null); } var note = new UserNote() { BookId = BookData.BookId, CreateDate = DateTimeOffset.Now, Location = location, Text = currSelection, }; await NoteEditor.EditNoteAsync(ControlId, note); }