I have 3 pages in my app. Page # 2 navigates back to page #1 and forward to Page # 3. How can I make it so navigating back from page #3 would skip page # 2 and go directly to #1?
What I ended up with, is combining pages #2 and #3 in one page. When I need page#2, I use navigation parameter to start the page with #2 content visible, when I'm done with #3, I simply hide #2 content.
EDIT: In Mango, there is a NavigationService.RemoveBackEntry() function that does exactly what is needed.
There's no way to go directly from page#3 to page#1 without going through page#2.
You could however handle OnNavigatedTo
in Page#2 and if coming from Page#3 then issue another call to NavigationService.GoBack()
.
Something like:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (comingFromPage3)
{
NavigationService.GoBack();
}
base.OnNavigatedTo(e);
}
There are various ways you could track if coming from page#3. I'd be tempted to go with a global variable to indicate this (set in page#3 and checked in page#2).
If you decide to use simple tracking of how many times the page has been navigated to (i.e. the second time the page is navigated to it must be in return from #3) be careful about what happens when tombstoned when either page#2 or page#3 is displayed.
If you are using the hardware back button, then no there is no direct way to do this.
You could always use the navigate method to go directly to page one.
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
That will get you to the first page but it will also add page 3 to the back stack.
In WPF you can always use the RemoveBackEntry() method to clear items from the back stack but unfortunately it's not available in Silverlight for the phone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With