Add OnClose confirmation dialog support for macOS (Catalyst) #29820
Replies: 1 comment 1 reply
-
Actually I would argue that adding this API would break cross-platform consistency. This will never be a concept on iOS and Android since they would not allow this. Therefore, we can only implement this for desktop platforms. I converted this to a discussion for now, I am pretty sure that we will not be adding this anytime soon, and likewise I am also pretty sure that we should be able to come up with a way to make this work with what is available in .NET MAUI today. Maybe someone can provide some ideas if they have done it already. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
In .NET MAUI (specifically for macOS via Catalyst), there is currently no way to intercept or cancel a window close event when the user clicks the red “X” button. This makes it impossible to prompt the user with a confirmation dialog (e.g., “Do you want to save before exiting?”) or to cancel the close operation.
This behavior is possible on native macOS (AppKit) and on Windows (via
AppWindow.Closing
orWindow.Closing
in WPF/WinUI). However, MAUI apps targeting Mac Catalyst are missing this capability, breaking cross-platform consistency and making it difficult to build reliable desktop apps that protect user data.Proposed outcome: Developers should be able to hook into a
Window.Closing
or similar event on macOS (Catalyst) and show a confirmation prompt. If the user cancels, the close operation should be aborted.Public API Changes
Here is a suggested API (subject to naming/design alignment):
Where:
e.Cancel = true
cancels the close action.Closing
is a new event onWindow
for macOS Catalyst (or across all platforms).This would mirror existing behavior on Windows and native Mac.
Alternatively, provide a virtual method in
App
like:Intended Use-Case
This feature is essential for desktop-like apps built in .NET MAUI that deal with user input, forms, documents, or stateful data—especially those that:
Ask users to fill in forms (survey apps, editors, etc.)
Manage documents or files (text editors, content tools)
Collect unsaved session data that must not be lost on accidental close
Example: A user fills a form in a .NET MAUI Mac Catalyst app. Before closing, the app should prompt:
“Are you sure you want to exit? Your changes will be lost.”
But currently, no Catalyst-specific MAUI lifecycle event supports this. Existing events like
Window.Stopped
orWindow.Destroying
are too late—the window is already closed and UI dialogs cannot be shown.This feature will bring parity with Windows and native macOS apps and make MAUI a better fit for cross-platform desktop experiences.
Beta Was this translation helpful? Give feedback.
All reactions