---
title: "How to catch the event of the window close button (red X button on window right top corner) in wpf form?"  
description: "How to catch the event of the window close button (red X button on window right top corner) in wpf form?"  
author: "Madam Walker"  
published: 2013-08-10  
updated: 2013-08-10  
canonical: https://www.mindstick.com/forum/1373/how-to-catch-the-event-of-the-window-close-button-red-x-button-on-window-right-top-corner-in-wpf-form  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How to catch the event of the window close button (red X button on window right top corner) in wpf form?

How to [catch](https://www.mindstick.com/forum/159341/how-to-use-try-and-catch-in-java-for-exception-handling-and-what-happens-when-an-exception-occurs) the [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) of the [window close](https://www.mindstick.com/forum/34365/refresh-parent-page-webgrid-on-window-close-in-mvc) [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) ([red](https://yourviews.mindstick.com/view/81343/lonar-lake-turning-red-again) X button on window [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) top corner) in wpf [form](https://www.mindstick.com/forum/6/multi-form-mfc-application)?

How to catch the event of the window close button(red X button on window right top corner) in wpf form ? We have got the closing event, window unloaded event also, but we want to show a [pop up](https://answers.mindstick.com/qa/50233/what-to-do-with-the-issues-that-may-pop-up-at-the-time-of-usb-device-installation) if he clicks the close button of the wpf form.

Help me Please.

## Replies

### Reply by Pravesh Singh

Use the Closing event in the [Window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript), you can handle it like this to prevent it from closing:

```
private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e){    e.Cancel = true;}
```


---

Original Source: https://www.mindstick.com/forum/1373/how-to-catch-the-event-of-the-window-close-button-red-x-button-on-window-right-top-corner-in-wpf-form

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
