Windows Phone: RemoveBackEntry after navigate failing

耗尽温柔 提交于 2019-12-24 04:21:18

问题


I've got an intermediate "Loading" page for my game: I send them there and it has "Loading..." text that displays while the rather hefty game page loads up:

private void OnLoaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
        {
            try
            {
                NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
                NavigationService.RemoveBackEntry();
            }
            catch (InvalidOperationException)
            {
            }
        });
}

Then when you hit the back button you go to the main page rather than back to the loading screen. There's no other logic on the page.

However I just got a store submission declined: apparently on the Samsung Focus and Odyssey the navigation entry for the loading page didn't get removed, and the user is sent back to the loading page when they hit the back button, rather than back to the main menu. I'm guessing RemoveBackEntry failed.

This looks like it should work, I can't reproduce the error and I don't have a Focus or Odyssey to work with. Does anybody know what might be going wrong?


回答1:


I think you should replace:

NavigationService.RemoveBackEntry();

with:

 while (NavigationService.CanGoBack)
 {
    NavigationService.RemoveBackEntry();
 }



回答2:


You have to remember that NavigationService.Navigate will perform the navigation asynchronously. So when you call NavigationService.RemoveBackEntry(), the current page might not yet be on the BackStack.

To fix that, call RemoveBackEntry in OnNavigatedTo of GamePage.



来源:https://stackoverflow.com/questions/21845184/windows-phone-removebackentry-after-navigate-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!