Everyone:

When working with winform applications, you could check the reason for
closing the window. As in this example:
private void MainForm_FormClosing(object sender,
FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
if (CloseApplication())
Application.Exit();

else
e.Cancel = true;

}
}

Now, e doesn't return a closereason. Is there anyway to check why the
window is closing?

Thanks,
Dale Williams

Re: WPF - Closing Application by Willy

Willy
Sat Mar 15 04:36:12 CDT 2008

"Dale Williams" <DaleWilliams@discussions.microsoft.com> wrote in message
news:E59BF068-D4A6-4226-BCDB-84AC4EF44D90@microsoft.com...
> Everyone:
>
> When working with winform applications, you could check the reason for
> closing the window. As in this example:
> private void MainForm_FormClosing(object sender,
> FormClosingEventArgs e)
> {
> if (e.CloseReason == CloseReason.UserClosing)
> {
> if (CloseApplication())
> Application.Exit();
>
> else
> e.Cancel = true;
>
> }
> }
>
> Now, e doesn't return a closereason. Is there anyway to check why the
> window is closing?
>
> Thanks,
> Dale Williams


Application life cycle is separated from the Window life cycle in WPF.
Application events must be handled by the Application event handlers.
Following snippet sample uses XAML to register the SessionEnding
handler.....


// XAML
<Application....
....
SessionEnding="App_SessionEnding">

// Code
public partial class App : Application
{
void App_SessionEnding(object sender, SessionEndingCancelEventArgs
e)
{
if(e.ReasonSessionEnding =
...
}

Consult MSDN for more info...

Willy.