Basically, what we want here is to be able to catch the close event of our UWP app. We could go further and ask the users if they want to save their changes before the Exit.

In the App.xaml.cs:

Here, it is important to put the CloseRequested event before the Activate of the View.

Then, add the code for the popup with the Exit confirmation:

If the user click on “No”, then we have e.Handled = true, which allows to keep the app open and cancel the Exit.

Then, open the code of the Package.appxmanifest and add this:

Happy coding! 🙂