Reputation: 11351
I have two questions here about Windows Phone page navigation:
NavigationService.Navigate("page_2_uri")
call in page 1?Thank you.
Upvotes: 0
Views: 510
Reputation: 26345
- Is there a way to get the instance of the page I am navigating to?
No.
- Is there a way I can know which page I navigate from?
Yes. Traverse the NavigationService.BackStack
Upvotes: 3
Reputation: 5785
The idea for using the NavigationService to navigate between pages is that you don't need to know any details about your destination. So in your example, Page 2 isn't initialized until you've left Page 1, and therefore Page 1 is no longer in scope, and won't be able to do anything with Page 2. If you want to pass information/context to Page 2, id recommend using Query Parameters (see next answer). If you want to know where the navigation is going, you can override the OnNavigatedFrom event and look at the Uri property of the NavigationEventArgs.
I would recommend looking at the NavigationContext property of the Silverlight Page class. This property lets you view the QueryString of the navigation request. Using this approach, you could navigate to page 3 using a uri like "page_3?previous_page=2" and then extract the previous_page from the QueryString of the NavigationContext to see where you came from.
Upvotes: 2