/// <summary> /// "Add product" button, to insert record to product DB. Open a new window with enabled "Name" textbox /// </summary> private void AddProductClick(object sender, RoutedEventArgs e) { ProductFormViewModel viewModel = new ProductFormViewModel(new Product()) { IsNew = true }; NewProductView newProduct = new NewProductView(false) { DataContext = viewModel }; newProduct.ShowDialog(); }
/// <summary> /// Similar to AddProduct in MainWindow. Difference: IsNew property = false, and give true overload to disable "Name" textbox when NewProductView opens /// </summary> private void ClickModify(object sender, RoutedEventArgs e) { if (selectedProduct != null) { ProductFormViewModel viewModel = new ProductFormViewModel(selectedProduct) { IsNew = false }; NewProductView newProduct = new NewProductView(true) { DataContext = viewModel }; newProduct.ShowDialog(); } else { MessageBox.Show("Please select a product first"); } }