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;
}
}
}
UWP怎么双击后退按钮完全退出应用
最新推荐文章于 2020-06-24 22:47:54 发布