Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I find out which page a user came from on Back Button press on WP7?

I haven't had much luck finding the answer through google searches, but is it possible to tell which page a user came from?

Or, send a query string on back button press, so I can tell?

Basically, I have a page that I don't want a user to get to by pressing the back button -- the only way they should get there is if they followed the process from the start. A good example of what I'm trying to do is not allow a user to go back to the confirmation setup while registering for an account after they have already successfully registered. I'd rather them go to the start of registration.

like image 976
Hosemeyer Avatar asked Aug 09 '11 15:08

Hosemeyer


1 Answers

You can use the NavigationService.BackStack property and check the first entry in the back stack in the page as it is navigated to.

If this check needs to be done in several pages, it could be put into a base class. Also, if your situation fits the eula/login scenario mentioned by @Skomski, his answer makes the most sense.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    var lastPage = NavigationService.BackStack.FirstOrDefault();

    if (lastPage != null && lastPage.Source.ToString() == "/MainPage.xaml")
    {
        NavigationService.RemoveBackEntry();
    }
}
like image 137
Jeff Ogata Avatar answered Sep 27 '22 18:09

Jeff Ogata