开发Windows Phone应用程序的时候,我在其它页面有写过这样的代码:
private void btCancel_Click(object sender, EventArgs e) { NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); }
导致了如下问题:
当经过该页面,点击Cancel返回到主页面MainPage后,再点击Back按钮,程序不会退出,而是重定向到这个页面。
解决办法如下,在MainPage的OnBackKeyPress中添加如下代码:
if (NavigationService.CanGoBack) { while (NavigationService.RemoveBackEntry() != null) { NavigationService.RemoveBackEntry(); } } base.OnBackKeyPress(e);
亲测过,果然管用