You can try to use the AppWindow.Closing Event to do that. Please put the following code into the App.cs's constructor.
#if WINDOWSusing Microsoft.UI.Windowing;#endif....... public App() { InitializeComponent(); Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => {#if WINDOWS var nativeWindow = handler.PlatformView; var appWindow = nativeWindow.GetAppWindow(); if (appWindow is not null) { appWindow.Closing += async (sender, args) => { args.Cancel = true; if (App.Current.MainPage != null) { bool value = await App.Current.MainPage.DisplayAlert("xxx", "xx", "yes", "no"); if(value == true) { nativeWindow.Close(); } } }; }#endif }); MainPage = new AppShell(); }