UWP怎么双击后退按钮完全退出应用

 private void M_BackRequested(object sender, BackRequestedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
                return;
            if (rootFrame.CurrentSourcePageType.Name !="MainPage")
            {
                if (rootFrame.CanGoBack && e.Handled == false)
                {
                    e.Handled = true;
                    rootFrame.GoBack();
                }
            } 
            else if(e.Handled == false)
            {

                StatusBar statusBar = StatusBar.GetForCurrentView();
                statusBar.ShowAsync();
                statusBar.ForegroundColor = Colors.White; // 前景色
                statusBar.BackgroundOpacity = 0.9; // 透明度
                statusBar.ProgressIndicator.Text = "再按一次返回键退出程序。"; // 文本
                statusBar.ProgressIndicator.ShowAsync();
                
                if (isExit)
                {
                    App.Current.Exit();
                }
                else
                {
                    isExit = true;
                    Task.Run(async () =>
                    {
                        //Windows.Data.Xml.Dom. XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                        //Windows.Data.Xml.Dom.XmlNodeList elements = toastXml.GetElementsByTagName("text");
                        //elements[0].AppendChild(toastXml.CreateTextNode("再按一次返回键退出程序。"));
                        //ToastNotification toast = new ToastNotification(toastXml);
                        //ToastNotificationManager.CreateToastNotifier().Show(toast);     

                        await Task.Delay(1500);
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            statusBar.ProgressIndicator.HideAsync();
                            statusBar.HideAsync();
                        });
                        isExit = false;
                    });
                    e.Handled = true;
                }
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值