What is the difference between NavigationService.Navigate() method and PhoneApplicationFrame.Source property?
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 开发者_JAVA百科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?
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.
精彩评论