WP7dev

Windows Phone 7 development tips

Tag Archives: navigation

Navigation exception : No Fragment support right now

This bug is Wp7’s most famous bug, when navigation to the same page as the one you’re currently on, you get an exception :

How to work around this ? First, you should never need to navigate to the same page as the one you’re already on, if your application does this, you should really reconsider why (and maybe read again Microsoft guidelines for WP7 development)

To avoid any crash, a simple way is to prevent navigating to the same page, I usually do this with this piece of code inserted in App.xaml.cs :

App.xaml.cs :


// prevents crash when trying to navigate to current page

public static void NavigateTo(string url)

{

    var frame = App.Current.RootVisual as PhoneApplicationFrame;

    if ((frame == null) || (url == frame.CurrentSource.ToString()))

        return;

    frame.Navigate(new Uri(url, UriKind.Relative));

}

 


Then, instead of using :

NavigationService.Navigate(new Uri(Views/MainPage.xaml”, UriKind.Relative));

use this :

App.NavigateTo(“/Views/MainPage.xaml”);

Advertisements