[英]UWP:Frame in Frame Back handeling
在我的新UWP应用中,我要处理后退按钮的框架中有一个框架。 视图看起来像这样:
注意:F =帧,P = PAge,红色=导航,蓝色=导航后退
我有一个母版页,可以导航到某些页面。 这些页面之一具有内部根框架,可导航到p4 onload。 并且p4可以导航到某些页面。 问题是,通过Microsoft的导航方式,我只能处理根框架(f1)或仅处理内部框架(f2)。
使用此代码:
public P3()
{
this.InitializeComponent();
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
else
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested +=
App_BackRequested;
}
~P3()
{
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
else
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested -=
App_BackRequested;
}
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
if (Frame == null)
return;
// Navigate back if possible, and if the event has not
// already been handled .
if (Frame.CanGoBack && e.Handled == false)
{
e.Handled = true;
Frame.GoBack();
}
}
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
if (Frame == null)
return;
// Navigate back if possible, and if the event has not
// already been handled .
if (Frame.CanGoBack && e.Handled == false)
{
e.Handled = true;
Frame.GoBack();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
F2.Navigate(typeof(P4));
if (Frame.CanGoBack)
{
// Show UI in title bar if opted-in and in-app backstack is not empty.
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Visible;
}
else
{
// Remove the UI from the title bar if in-app back stack is empty.
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
AppViewBackButtonVisibility.Collapsed;
}
}
看来您的Page3中有一个名为F2的框架。 这是您要用于回溯的框架。 因此,您需要像这样更改后退导航
public P3()
{
this.InitializeComponent();
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
if (F2 == null)
return;
// Navigate back if possible, and if the event has not
// already been handled .
if (F2.CanGoBack && e.Handled == false)
{
e.Handled = true;
F2.GoBack();
}
}
请注意,您使用的是Frame
,它是Page本身的属性,可以访问页面的父Frame。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.