How to catch the event of the window close button(red X button on window right top corner) in wpf form?

Use the Closing event in the Window, you can handle it like this to prevent it from closing:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
}

Leave a Comment