private void AddNewNoteButton_Click(object sender, RoutedEventArgs e) { NoteEditWindow addNoteEditWindow = new NoteEditWindow() { DataContext = new NoteEditViewModel() { ParentViewModel = (this.NoteDisplayGrid.DataContext as ViewModelBase), NoteModel = new NoteModel(), NoteEditType = NoteEditType.Add } }; addNoteEditWindow.ShowDialog(); }
private void ModifyNoteButton_Click(object sender, RoutedEventArgs e) { Button modifyButton = sender as Button; if (modifyButton != null) { NoteModel noteModel = modifyButton.DataContext as NoteModel; if (noteModel != null) { NoteModel newNoteModel = noteModel.Clone() as NoteModel; if (newNoteModel == null) { //newNoteModel=new NoteModel(); MessageBox.Show("数据赋值出错,请检查"); return; } NoteEditViewModel modifyViewModel = new NoteEditViewModel() { ParentViewModel = this.DataContext as ViewModelBase, NoteModel = newNoteModel, NoteEditType = NoteEditType.Modify }; NoteEditWindow modifyNoteEditWindow = new NoteEditWindow() { DataContext = modifyViewModel }; modifyNoteEditWindow.ShowDialog(); } } }