I have this application schema :
[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
^__________________|
Have a look at simple library i wrote for such purposes: http://navcoerce.codeplex.com/
var fluent = new FluentNavigation(RootFrame);
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<LoginPage>()
.ThenToAnyPage()
.RemoveEntriesFromBackStack(1);
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<LoginPage>()
.ThenTo<RegisterPage>()
.ThenTo<PaymentPage>()
.RemoveEntriesFromBackStackTill<MainPage>();
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<SecondPage>()
.ThenTo<RegisterPage>()
.ThenOptionallyTo<ForgotPasswordPage>()
.ThenToAnyPage()
.RemoveEntriesFromBackStackTill<MainPage>();
fluent.WhenNavigatingTo<PaymentPage>()
.RedirectTo<LoginPage>();
fluent.WhenNavigatingTo<PaymentPage>()
.If(() => false)
.RedirectWithReturnUri<LoginPage>("ReturnUri");
I have a similar situation in my app, i solve it with a very simple solution.
If you want to "skip" a page in your backstack, place some logic in the NavigatedTo() function of that page.
For example: you can have a bool that you set to true when you post to facebook, and then place the following code in the NavigatedTo() function of the ShareOnFacebook page.
Here is pseudo code:
if (alreadyPosted)
Navigation.GoBack();
The GoBack() function will skip this page and return to the previous one, the user will never see the page.
I use the removeBackEntry
method on the NavigationService
Class. I also use this as a way to setup my own splash screens
private void BWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// switch screen
NavigationService.Navigated += new NavigatedEventHandler(NavigationServiceNavigated);
NavigationService.Navigate(new Uri("/Pages/main.xaml", UriKind.Relative));
}
void NavigationServiceNavigated(object sender, NavigationEventArgs e)
{
NavigationService.RemoveBackEntry();
}
Have a look at the new Nonlinear Navigation Service recipe
Download it from http://create.msdn.com/en-us/education/catalog/article/nln-serv-wp7
I posted an example for the same issue here.
The Nonlinear Navigation Service Matt linked to essentially does the same thing but would probably be better than my simple example.
Try this: Call NavigationService.RemoveBackEntry();
in the OnNavigatedTo
method. This will remove the previous page from the stack. In my opinion the trick with Navigation.GoBack();
is not satisfying because it shows the page to remove for a short time.
Note: Works only with Windows Phone OS 7.1 (Mango) SDK