how to prevent going back to previous page

2019-02-20 16:17发布

问题:

For a windows phone 8 app I'm developing, I had to load some data at the starting of the app. For that matter I designed a page called SplashScreen.xaml that loads the data and after all the loading is done I navigate to the MainPage.xaml using:

    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));

Now when the user is in the main page and taps the back button on the phone instead of going out of the app(which is the default gesture) goes back to the SplashScreen.xaml, making them unable to go out of the app(except for taping the start button which take's the app to background) and of course giving them a bad impression. The question is How to prevent going back to the previous page Thank you all.

回答1:

Just clear the backstack when landing on MainPage:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    while (NavigationService.RemoveBackEntry() != null);
}