Hello. I want to ask user before closing application. I's C#.NET 4.0 application. I'm using WPF. I can do it in windows forms, but not in WPF. Event is fired when user want to close app, message Box appears, bun no matter which button is pressed(Yes or No) application always closes. Why? Where is mistake?
It works, but only when user press "X". When user press button with Application.Current.Shutdown(); it is not working.
private void MainWindowDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult result = MessageBox.Show("Do you really want to do that?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
e.Cancel = true;
}
}