【发布时间】:2016-04-14 14:31:41
【问题描述】:
我有带有 Prism 和 AppShell 的 UWP 应用程序。 我想在 BackButton 退出之前添加确认对话框。 我试过这个:
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
...
SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
...
}
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
return;
}
if (rootFrame.CanGoBack && e.Handled == false)
{
<add confirm dialog here>
e.Handled = true;
}
}
但 rootFrame 始终为空,如果历史堆栈为空并且我按下 BackButton 应用程序关闭,即使 imake 如下:
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
e.Handled = true;
}
我也试过了
HardwareButtons.BackPressed += App_BackRequested;
它也无济于事。
【问题讨论】:
标签: c# xaml win-universal-app prism