【发布时间】:2015-10-28 05:13:04
【问题描述】:
在我的 Xaml 页面中,我有一个框架。
我正在尝试让 backButton 事件在框架内导航。
所以我尝试使用这段代码
public MainPage(){
this.InitializeComponent();
if(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) {
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
}
private void HardwareButtons_BackPressed(object sender,BackPressedEventArgs e) {
if(insideFrame.CanGoBack())insideFrame.GoBack();
else Application.Current.Exit();
}
但在手机中执行HardwareButtons_BackPressed 事件后它会关闭应用程序。
似乎在 MainPage 上运行了一些默认的后退按钮行为...
我该如何解决?在 Windows10 中他们是否添加了新事件来处理返回导航?
[更新]
现在我发现在 Windows 10 中使用 SystemNavigationManager 比使用 Input.HardwareButtons.BackPressed 更好。
SystemNavigationManager currentView = SystemNavigationManager.GetForCurrentView();
【问题讨论】:
-
SystemNavigationManager的使用可以在以下博客中找到:wintellect.com/devcenter/jprosise/… -
@Shahriar 这也适用于 Windows 10 Mobile。因为我检查过,Windows Mobile 中不显示后退按钮。
标签: c# navigation windows-10 windows-10-mobile