uid |
---|
Uno.Features.AppCloseHandler |
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 Alt+F4. 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 Closing
event will still be raised, but setting args.Cancel = true
has 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.Closing
event must be handled synchronously. Asynchronous operations (e.g., showing a ContentDialog
) are not allowed and will not delay the closing process.