protected override void Update(object sender, RoutedEventArgs e) { // Opens an update form in a popup window CategoryOverviewItem cat = ((FrameworkElement)sender).DataContext as CategoryOverviewItem; ShowUpdateForm <CategoryForm>(cat.ID); }
protected override async void Delete(object sender, RoutedEventArgs e) { try { // Gets the item that has to be deleted CategoryOverviewItem ToBeDeleted = ((FrameworkElement)sender).DataContext as CategoryOverviewItem; // Create custom message box string messageboxTitle = String.Format(LangResource.MBTitleDeleteObj, ToBeDeleted.LocalizedName); string messageboxContent = String.Format(LangResource.MBContentDeleteObj, LangResource.TheCategory.ToLower(), ToBeDeleted.LocalizedName); MessageBoxManager.Yes = LangResource.Yes; MessageBoxManager.No = LangResource.No; MessageBoxManager.Register(); // If people are sure to delete... if (MessageBox.Show(messageboxContent, messageboxTitle, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { MessageBoxManager.Unregister(); // ... then delete the object _catRepo.Delete(ToBeDeleted.ID); CategoryList.Remove(ToBeDeleted); await _catRepo.SaveChangesAsync(); // And refresh the datagrid BindData(); } else { MessageBoxManager.Unregister(); } } catch (Exception) { MessageBoxManager.Unregister(); MessageBox.Show(LangResource.ErrUpdateOverviewFailed); } }