Windows phone 8.1 Windows phone 8.1背压无法正常工作
Windows phone 8.1全新面世。基本功能是返回按钮点击。此windows phone 8.1的功能是否工作不正常。是那种行为,还是我犯了错误 下面的代码在主页中使用,但此代码在单击“上一步”时也从所有其他类调用。我需要访问以下方法只在主页上 请检查下面的代码,并向我推荐好的解决方案 请查看我的代码:Windows phone 8.1 Windows phone 8.1背压无法正常工作,windows-phone-8.1,Windows Phone 8.1,Windows phone 8.1全新面世。基本功能是返回按钮点击。此windows phone 8.1的功能是否工作不正常。是那种行为,还是我犯了错误 下面的代码在主页中使用,但此代码在单击“上一步”时也从所有其他类调用。我需要访问以下方法只在主页上 请检查下面的代码,并向我推荐好的解决方案 请查看我的代码: public HomePage() { this.InitializeComponent(); Windows.Phone.UI.Input.HardwareButtons
public HomePage()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
}
谢谢它工作正常。整个应用程序都在运行。我想到了两个选择:
- 编写能够识别当前调用它的页面的eventhandler-简单示例如下所示:
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e) { Frame frame = Window.Current.Content as Frame; if (frame == null) return; if (frame.Content is HomePage) { e.Handled = true; Debug.WriteLine("I'm in HomePage"); } else if (frame.CanGoBack) { frame.GoBack(); e.Handled = true; } }
- 第二个选项-订阅
,离开页面时取消订阅。请注意,这种方式存在一些缺陷-您必须正确处理OnNavigatedTo、OnNavigatedFrom、挂起和恢复(更多关于)。还请注意,订阅应该在其他订阅之前完成,例如NavigationHelperWindows.Phone.UI.Input.HardwareButtons。进入页面时按
- 如果之前(在App.xaml.cs中)有其他订阅的
——请记住,事件通常是按订阅顺序触发的BackPressed
- 检查您是否正在使用NavigationHelper-它还订阅了
BackPressed
- 记住不要订阅多次
- 请记住允许用户离开您的主页