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.
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.