views:

938

answers:

1

Taken from Exercise 1: Creating Windows Phone Applications with Microsoft Visual Studio 2010 Express for Windows Phone

Task 3: Step 9

// navigate
this.NavigationService.Navigate(new Uri("/PuzzlePage.xaml", UriKind.Relative));

Note:
The PhoneApplicationPage class provides methods and properties to navigate to pages through its NavigationService property. You can call the Navigate method of the NavigationService and pass the URI for the page as a parameter. You can also use the GoBack and GoForward methods to navigate backward or forward in the navigation history. The hardware back button also provides backward navigation within an application. The event handler shown above uses the NavigationService to go to the PuzzlePage.xaml page.

Task 4: Step 3

(RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = 
    new Uri("/ErrorPage.xaml", UriKind.Relative);

Note:
...
Whenever you set the Source property to a value that is different from the displayed content, the frame navigates to the new content.
...

What are the differences and similarities of both techniques?

+3  A: 

Essentially, they both do the same thing.

NavigationService.Navigate is a native Silverlight navigation service to allow the asynchronous navigation from one xaml file to another (eliminating the need to load usercontrols) - there's an excellent little overview here.

The difference is that NavigationService has the ability to go backward and forward in a browser-esque fashion. Setting the Source property of the PhoneApplicationFrame does not.

Still early days and it's probably too soon to make an educated guess as to which you should use.

NavigationService has the advantage of being a Silverlight-native class, however PhoneApplicationFrame.Source is specific to WP.

Daniel May
PhoneApplicationFrame.Source is inherited from Frame, and is thus not specific to Windows Phone. I can't test it right now, but I do think that you can navigate through the page stack even when using the Source property.One difference between the Navigate method and the Source property is that you cannot call Navigate on a page that has not been loaded yet, whereas you can set the Source property whenever you want to.
Andréas Saudemont
"you cannot call Navigate on a page that has not been loaded yet"? Does this mean I cannot navigate to a page that has never been navigated to before? Very confusing.
Ryan Pedersen