Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 446

Answer by Liyun Zhang - MSFT for How does the MAUI Windows App pop up a second-confirmation dialog while close window?

$
0
0

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();        }

Viewing all articles
Browse latest Browse all 446

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>