OnBackKeyPress未按预期工作

时间:2014-02-03 13:50:36

标签: c# windows-phone-8

在我的应用程序中,我有这两个功能。自从我添加OnBackKeyPress函数后,if内的OnNavigatedFrom语句即使我按下后退按钮也是如此(可能是因为e.cancel= true; OnBackKeyPress内部protected override void OnNavigatedFrom(NavigationEventArgs e) { // On back navigation there is no need to save state. if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back) { StoreState(); //this should not run when i press back button } FilterPreviewPivot.SelectionChanged -= FilterPreviewPivot_SelectionChanged; base.OnNavigatedFrom(e); } protected override void OnBackKeyPress(CancelEventArgs e) { while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry(); NavigationService.Navigate(new Uri("/Chooser.xaml", UriKind.Relative)); // cancel the navigation e.Cancel = true; }

{{1}}

1 个答案:

答案 0 :(得分:0)

由于您在e.cancel = true中设置了OnBackKeyPressNavigationMode中的Back将不会是OnNavigatedFrom

尝试在页面中使用全局变量,默认情况下为false,并在true中将其设置为OnBackKeyPress。然后,在OnNavigatedFrom中检查此变量而不是NavigationMode.Back

相关问题