Paul
Paul

Reputation: 1019

Change URI of main page after app was opened by a custom URI

I use custom URIs to open my app on Windows Phone 8. When the device receives a URI with my custom protocol a custom UriMapper extracts the parameters and returns a URI of the form /MainPage.xaml?param1=test. This opens the main page which in turn uses the parameters to do something.

The problem: If the app is being opened with a custom URI, the custom URI stays in the back-stack. If I then open a sub page and navigate back with the back button the main page gets loaded with the parameters, which results in the app processing the parameters again. I want to replace the URI in the back-stack with a parameter-less version once the parameters have been processed.

Upvotes: 1

Views: 149

Answers (1)

Mark
Mark

Reputation: 8291

If you find a parameter you could remove the current page (with navigation from the stack) and navigate again to the same page like this:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    if (this.NavigationContext.QueryString.ContainsKey("param1"))
    {
        string param = this.NavigationContext.QueryString["param1"]; //Get "Param" this QueryString. 

        // .. Do Stuff

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

    }
}

HTH

Upvotes: 2

Related Questions