How to use Application.Exit Event in WPF?

后端 未结 5 754
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 14:29

I need to delete some certain files, then user closes program in WPF. So I tried MDSN code from here http://msdn.microsoft.com/en-us/library/system.windows.application.exit.

5条回答
  •  再見小時候
    2020-12-05 15:12

    If you want to follow MVVM principle you can use System.Windows.Interactivity.WPF.

    MainWindow.xaml

    
    
    
        
            
        
    
    

    MainWindowViewModel.cs

    public class MainWindowViewModel 
    {
        ICommand WindowClosingCommand => new RelayCommand(arg => this.WindowClosing());
    
        private void WindowClosing()
        {
          // do what you want.
        }
    }
    

    This approach is more testable. Have a nice day.

提交回复
热议问题