Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a page from Navigation Stack

I have this application schema :

[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
                     ^__________________|
  1. The user select an Item in the [List Page]
  2. The user may or may not click a Share button if he or she does, the application navigates to a [ShareOneFacebook page] which displays a Facebook Login Form, posts a message and navigates back
  3. The user navigates back.

If the user shared on facebook, it will "repost" the message, because the application store the session so it will navigate back to ShareOnFacebook, and then back to my Detail page.

If the user didn't share, he goes back to the List Page.

How can I "ommit" the ShareOnFacebook page in my navigation stack ?

like image 461
Thomas Joulin Avatar asked Dec 14 '10 15:12

Thomas Joulin


3 Answers

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

like image 79
Rico Suter Avatar answered Nov 21 '22 14:11

Rico Suter


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.

like image 21
Amr H. Abd Elmajeed Avatar answered Nov 21 '22 16:11

Amr H. Abd Elmajeed


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");   
like image 44
Grigory Avatar answered Nov 21 '22 16:11

Grigory