In WPF I want to change default close behaviour of some window, so that when user clics red close button the window does not close, it merely hides (and call some method as well). How can I do that?
+3
A:
This page should help.
Closing can be handled to detect when a window is being closed (for example, when Close is called). Furthermore, Closing can be used to prevent a window from closing. To prevent a window from closing, you can set the Cancel property of the CancelEventArgs argument to true.
And
If you want to show and hide a window multiple times during the lifetime of an application, and you don't want to reinstantiate the window each time you show it, you can handle the Closing event, cancel it, and call the Hide method. Then, you can call Show on the same instance to reopen it.
esalaka
2010-06-08 21:47:06
+4
A:
Try overriding OnClosing in Window.xaml.cs
private override void OnClosing( object sender, CancelEventArgs e )
{
e.Cancel = true;
//Do whatever you want here..
}
Jobi Joy
2010-06-08 21:49:01