views:

20

answers:

1

When the user closes my application I'd like to be able to prompt them with a confirmation if they have unsaved changes, and cancel the application's closing if they indicate to do so. The Application's Exit event does not allow cancellation. Is there any way to do this?

A: 

Catch the Closing event of the MainWindow instead:

App.Current.MainWindow.Closing += MainWindow_Closing;

Then you can set the Cancel property to true in the event handler if necessary:

private void MainWindow_Closing(object sender, System.ComponentModel.ClosingEventArgs e)
{
    e.Cancel = true;
}

Hope this helps...

Chris

Chris Anderson
I also found this question which explained why this wasn't working for me. http://stackoverflow.com/questions/3591446/mainwindow-closing-event-not-always-raised-in-silverlight-4-oob-app
Matt Casto