How can I catch the event of the window close button(red X button on window right top corner) in a WPF form? We have got the closing event, window unloaded event also, but w
at form1.Designer.cs put below code to assign the event
this.Closing += Window_Closing;
at form1.cs put the closing function
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //change the event to avoid close form e.Cancel = true; }