protected override void OnCloseRequested(CloseEventHandlerArgs args) { if (!Modified) { base.OnCloseRequested(args); return; } MessageBoxResult result = System.Windows.MessageBox.Show( "Do you want to save changes before closing?", "Confirm", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { Modified = true; } else if (result == MessageBoxResult.No) { Restore(); Modified = false; } else if (result == MessageBoxResult.Cancel) { return; } base.OnCloseRequested(args); }
private void ViewModel_CloseRequested(object sender, CloseEventHandlerArgs args) { if (ViewModel.Modified) { ViewModel.CloseRequested -= ViewModel_CloseRequested; Save(); } }
void TabControlViewModel_CloseRequested(object sender, CloseEventHandlerArgs args) { BaseViewModel viewModel = sender as BaseViewModel; OpenTabItems.Remove(GetTabFor(viewModel)); }