コード例 #1
0
        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);
        }
コード例 #2
0
 private void ViewModel_CloseRequested(object sender, CloseEventHandlerArgs args)
 {
     if (ViewModel.Modified)
     {
         ViewModel.CloseRequested -= ViewModel_CloseRequested;
         Save();
     }
 }
コード例 #3
0
        void TabControlViewModel_CloseRequested(object sender, CloseEventHandlerArgs args)
        {
            BaseViewModel viewModel = sender as BaseViewModel;

            OpenTabItems.Remove(GetTabFor(viewModel));
        }