// Edit item private void editItemButton_Click(object sender, RoutedEventArgs e) { // Exit if no product selected if (model.SelectedItem == null) return; // Create a product detail model ItemDetailViewModel detailModel = new ItemDetailViewModel(model.SelectedItem); // Start editing detailModel.BeginEdit(); // Show ProductDetail view ItemDetailView itemDetail = new ItemDetailView(detailModel); itemDetail.Closed += (s, ea) => { if (itemDetail.DialogResult == true) { // Confirm changes detailModel.EndEdit(); } else { // Reject changes detailModel.CancelEdit(); } }; itemDetail.Show(); }
// Add item private void addItemButton_Click(object sender, RoutedEventArgs e) { // Create a product detail model Item newItem = new Item(); ItemDetailViewModel detailModel = new ItemDetailViewModel(newItem); // Show ProductDetail view ItemDetailView itemDetail = new ItemDetailView(detailModel); itemDetail.Closed += (s, ea) => { if (itemDetail.DialogResult == true) { model.Add(newItem); } }; itemDetail.Show(); }