The Windows Phone application I’m working on is made up of several list views where each item has quite similar detail views. In order to avoid duplicating views the idea was to create a single list page and use a sort of WPF’s DataTemplateSelector to select proper ItemTemplates so that same view can appear completely different to the final user. The idea works like a charm like navigation from list to detail page too apart a little problem arised when I encountered a special case: When an item is selected, instead of navigating to Item’s detail I need to navigate to a different list containing selected item’s children.
The problem is that from inside “MyListView.xaml” you can’t ask NavigationService to navigate to the same view (like my case) because it’s smart enough to tell you. “Hey!, you’re already on MyListView.xaml”, the trick is indeed very simple and it relies on passing parameters to target navigation Uri, something like:
public void NavigateTarget()
{
Uri target = new Uri(string.Format("MyListView.xaml?Id={0}", Guid.NewGuid()));
NavigationService.Navigate(target);
}
Being id parameter different, NavigationService navigate (thus reloads) the same page and properly put current page on backstack so that you can automatically show it pressing Back button.
It’s easy, it works, I like it!