Search code examples
xamlwindows-phone-8windows-phone-8.1

WP8.1 Silverlight - BackNavigation maintains the old NavigationEventArgs for OnNavigatedTo function


I am working on a Windows Phone 8.1 Silverlight app. In this app I have a launch string attached to the toast notification which helps in navigating to the MainPage with some parameters for e.g /MainPage.xaml?data=test

So when I click this notification, I am able to get this data value from NavigationEventArgs of OnNavigatedTo function of MainPage. Based on some logic associated with data I navigate to a new Test.xaml screen.

The problem is when I GoBack from this Test.xaml screen to MainPage.xaml, the old OnNavigatedTo NavigationEventArgs remains the same, i.e the Uri in NavigationEventArgs is being preserved.

Is there a way to delete the NavigationEventArgs once done and dealt with?


Solution

  • Please check the NavigationMode inside the OnNavigatedTo method on your main page for example if you will come back form test.xaml page e.NavigationMode==NavigationMode.Back will call and you can code there.

    protected override void OnNavigatedTo ( NavigationEventArgs e )
        {
    
                if ( e.NavigationMode==NavigationMode.New )
                {
                    //do somthing 
                }
    
                if ( e.NavigationMode==NavigationMode.Back )
                {
                   //do somthing 
                }
            }
    
        }