Thursday, December 22, 2011

How to check if back button is clicked or not when page transition is occurred

In the situation of page transition, sometime you may want to check page transition is occurred by pressing back button or not.



Today I introduce how to check  if back button is clicked or not when page transition is occurred.
It's easy to make it. You can use NavigationMode Enumeration in OnNavigatedTo method. When back button is clicked, NavigationMode Enumeration should be NavigationMode.Back.

Please check bellow code sample.

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

    //if the page transition is occurred by pressing back button.
    if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
    {
        //do something
    }
}

As you know OnNavigatedTo is called when page transition is occurred.

No comments:

Post a Comment