Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override onclose event on WPF?

Tags:

c#

wpf

I'm trying to override the onclose event on WPF, this is my code so far:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
       base.OnClosing(e);
       e.Cancel = true;
       //do my stuff before closing
}

It executes the code but the application never closes. Any ideas how to fix this?

like image 495
HoBa Avatar asked Apr 25 '11 03:04

HoBa


2 Answers

The application never closes because you are setting e.Cancel to true.

Try

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
       //do my stuff before closing

       base.OnClosing(e);       
}
like image 120
Bala R Avatar answered Nov 17 '22 08:11

Bala R


You are asking it not to close by setting e.Cancel = true. Just don't do that.

like image 35
Rick Sladkey Avatar answered Nov 17 '22 08:11

Rick Sladkey