Remove a page from Navigation Stack

前端 未结 6 1431
暖寄归人
暖寄归人 2021-01-11 11:05

I have this application schema :

[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
                     ^__________________|
    <
相关标签:
6条回答
  • 2021-01-11 11:11

    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");   
    
    0 讨论(0)
  • 2021-01-11 11:21

    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.

    0 讨论(0)
  • 2021-01-11 11:23

    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();
        }
    
    0 讨论(0)
  • 2021-01-11 11:29

    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

    0 讨论(0)
  • 2021-01-11 11:31

    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.

    0 讨论(0)
  • 2021-01-11 11:33

    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

    0 讨论(0)
提交回复
热议问题