private void AddNewBookButton_Click(object sender, RoutedEventArgs e) { var window = new DialogVM(null); var dialog = new Dialog() { Title = "New Book", DataContext = window }; if (dialog.ShowDialog() ?? false) { items.Add(window.Result); } }
private void ShowEditDialog() { if (BookList.SelectedItems.Count == 1) { if (BookList.SelectedItem is Book book) { DialogVM model = new DialogVM(book); Dialog dialog = new Dialog() { Title = "Edit Book", DataContext = model }; dialog.ShowDialog(); } } else if (BookList.SelectedItems.Count == 0) { MessageBox.Show("Select an item to edit.", "Warning"); } else { MessageBox.Show("Select only one item to edit.", "Warning"); } }