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 or Window.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):
window.Closing += (s, e) =>
{
if (hasUnsavedData)
{
bool result = await Application.Current.MainPage.DisplayAlert(
"Confirm Exit",
"You have unsaved data. Do you really want to close?",
"Yes", "No");
if (!result)
{
e.Cancel = true; // prevent close
}
}
};
Where:
e.Cancel = true cancels the close action.
Closing is a new event on Window 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:
public override bool OnWindowClosing(Window window)
{
// Custom logic to cancel or allow closing
return true; // or false to cancel
}
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 or Window.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.
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.ClosingorWindow.Closingin 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.Closingor 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 = truecancels the close action.Closingis a new event onWindowfor macOS Catalyst (or across all platforms).This would mirror existing behavior on Windows and native Mac.
Alternatively, provide a virtual method in
Applike: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.StoppedorWindow.Destroyingare 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.