Search code examples
windows-phone-8windows-phonewindowsnavigationservice

Check if the current page has been reached by pressing the back button


I'm developing a little app for Windows Phone 8 that has 2 pages (1 is of course the main page).

When page2 is reached I want to check if this page has been reached by pressing the back button on the phone. I want to do something like this:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (backButton.isPressed()) {
        // this page has been reached by pressing the back button on the phone
    } else {
        // this page has been reached by NavigationService.Navigate()
    }
}

Is there a native API to do that?


Solution

  • Is this what you need?

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e.NavigationMode == NavigationMode.Back)
        {
            ...
        }
    }