Clearing backstack in NavigationService

前端 未结 2 1473
滥情空心
滥情空心 2020-12-19 03:52

I am navigating through different pages within my application. After I login, I come to home page from where the navigation starts. During navigation, when I come to homepag

相关标签:
2条回答
  • 2020-12-19 04:00

    While I know the original question was for 7, in Windows Phone 8.1 the NavigationService no longer exists.

    Here is the Windows Phone 8.1 code

     var previousPage = this.Frame.BackStack.FirstOrDefault();
    
     if (previousPage != null && previousPage.SourcePageType == typeof(MainPage))
     {
         this.Frame.BackStack.RemoveAt(this.Frame.BackStackDepth - 1);
     }
    
    0 讨论(0)
  • 2020-12-19 04:20

    You can use NavigationService.RemoveBackEntry: http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.removebackentry%28v=VS.92%29.aspx

    For instance, to remove all entries from the stack:

    while (this.NavigationService.BackStack.Any())
    {
       this.NavigationService.RemoveBackEntry();
    }
    


    Also, if you want to remove only the previous page after checking its URI:

    var previousPage = this.NavigationService.BackStack.FirstOrDefault();
    
    if (previousPage != null && previousPage.Source.ToString().StartsWith("/MainPage.xaml"))
    {
        this.NavigationService.RemoveBackEntry();
    }
    
    0 讨论(0)
提交回复
热议问题