Search code examples
c#wpfwindow

How to override default window close operation?


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?


Solution

  • Try overriding OnClosing in Window.xaml.cs

    private override void OnClosing( object sender, CancelEventArgs e )
    {
         e.Cancel = true;
         //Do whatever you want here..
    }