Redirecting Navigation in Windows Phone 8

I am working on an app for Windows Phone 8 that uses some custom navigation. I made a class that inherits from UriMapperBase and set it into the RootFrame during application startup. In this mapper I can handle custom Protocols and redirect them to pages in my application.

I also use this mechanism to forward the user to a page to ask them to allow or deny the app rights to use the location services the first time its loaded up. This resulted in a strange case where I was actually redirecting the user to a page other than what they were actually navigating to. When I then attempted to navigate them to the correct page it ended up being a no-op since the current page was at the top of the navigation stack as the uri I was attempting to navigate to. In other platforms the NavigationService has a Refresh method you can call to resolve such problems but in Windows Phone 8 it is mysteriously missing. So after wasting a couple hours I managed to find a way to resolve this cunundrum.

Simply create a page in your application called Refresh.xaml and Navigate to this page. Something like this:

private void OnAllowClick(object sender, RoutedEventArgs e)
  LocationService.AllowLocationServices = true;
  this.NavigationService.Navigate(new Uri("/Views/Refresh.xaml", UriKind.Relative));

Then in Refresh.xaml you simply pop the last item off the navigation stack and navigate back to it:

public partial class Refresh : PhoneApplicationPage
  public Refresh()
  protected override void OnNavigatedTo(NavigationEventArgs e)
    var j = this.NavigationService.RemoveBackEntry();
    this.Dispatcher.BeginInvoke(() => App.RootFrame.Navigate(j.Source));
  protected override void OnNavigatedFrom(NavigationEventArgs e)

This will refresh to the current uri and preserve the navigation stack correctly.

Author: justinmchase

I'm a Software Developer from Minnesota.

Drop a brain bomb

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.