0

How to catch the OnClosing event like WinForm on uwp?

On desktop, we always close the app by clicking the "Close" button on the top-right corner.

I want to do something before closing.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
Vincent
  • 3,124
  • 3
  • 21
  • 40
  • This is not an easy question to answer... depends a bit on what you want to do, because the lifecycle of an UWP app is different than traditional apps. So take a look here https://learn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle that should help you decide. – Depechie Nov 06 '17 at 09:58
  • Paint 3D can do it before you closing it. It will ask you to save the work. I want this. – Vincent Nov 06 '17 at 10:10
  • Readup on this here https://learn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle#app-close – Depechie Nov 06 '17 at 10:14
  • I'm still confused, they don't give samples, just a few words. – Vincent Nov 06 '17 at 13:48
  • Maybe this example can help you more https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BasicSuspension – Depechie Nov 06 '17 at 13:51

1 Answers1

2

By default, you can't. But you can use the confirmAppClose capability to override the close button. To use this capability, you need to add it on your appxmanifest, AND, ask Microsoft to get the certification.

Override Close Box on Window 10 Universal Apps UWP

Mamoru Satoh
  • 2,670
  • 23
  • 23