doc/articles/features/app-close-handler.md
[!TIP] This article covers Uno Platform–specific behavior. For the full API documentation, see AppWindow.Closing Event.
The AppWindow.Closing API lets you respond to or prevent standard app window closing requests—such as clicking the window’s close button or pressing <kbd>Alt</kbd>+<kbd>F4</kbd>. Note that this does not block the user from terminating the app by force (e.g., via Task Manager or kill).
| Feature | Windows App SDK | Android | iOS | Web (WASM) | Desktop (Windows) | Desktop (macOS) | Desktop (Linux) |
|---|---|---|---|---|---|---|---|
AppWindow.Closing | ✔️ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ |
[!NOTE] On platforms where this feature is not supported, the
Closingevent will still be raised, but settingargs.Cancel = truehas no effect.
MyWindow.AppWindow.Closing += OnAppWindowClosing;
private void OnAppWindowClosing(AppWindow sender, AppWindowClosingEventArgs args)
{
// Replace with your own logic, such as checking for unsaved changes
bool cancelClose = ShouldWindowStayOpen();
// Cancel the close request if needed
args.Cancel = cancelClose;
}
[!IMPORTANT] The
AppWindow.Closingevent must be handled synchronously. Asynchronous operations (e.g., showing aContentDialog) are not allowed and will not delay the closing process.