views:

60

answers:

1

I'm developing a Silverlight wp7 app. I'm not sure exactly how to do navigation.

I have several PhoneApplicationPage classes, which contain several UserControls. It looks like I can use NavigationService to navigate from the PhoneApplicationPage classes, but not the UserControl classes. Is that preferable? Is the general pattern not to navigate directly from a UserControl, but to handle it from a PhoneApplicationPage?

Currently, I have a collection of content separated into sections. Each section has its own PivotItem in a PivotControl. The content for each section is in a ListBox. I wrapped the ListBox in a UserControl to provide a little more functionality/managing the content. However, it looks like I can't navigate directly from this class.

I could remove the wrapper and just put the functionality in the pivot page directly. But what if I want to repeat the content list elsewhere in my app?

Alternatively, I pass NavigationService to the UserControl when it's constructed by the PhoneApplicationPage.

+1  A: 

In WPF, it would be simple: You'd call the static method on NavigationService to get your answer: NavigationService.GetNavigationService(this).

Unfortunately, this does not appear to be available in WP7.

Instead, I came up with this hack... It is ugly as sin... hopefully there is something better. Possibly, at least, you can come up with something a bit more pretty. At least do some null checking...

var service = ((Application.Current as App).RootFrame.Content as Page).NavigationService;
Brian Genisio