清除导航服务中的后台堆栈

发布于 2024-12-17 09:45:44 字数 194 浏览 0 评论 0原文

我正在浏览应用程序中的不同页面。登录后,我从导航开始的地方进入主页。在导航过程中,当我进入主页时,我想通过按 BackKey 转到登录页面,但我只能导航到之前导航过的页面。我可以重写 BackKeyPress 事件以导航到登录页面,但在 LoginPage 中我应该再次重写 Backkeypress,否则按下后键时登录页面和主页之间会出现循环。有没有办法清除导航历史记录?

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 homepage, I want to go to the login page by pressing BackKey but I can only navigate to previously navigated page. I could have overriden the BackKeyPress event to navigate to the Login Page but in LoginPage I should again override the Backkeypress otherwise there appears to be cycle between loginpage and homepage on backkey press. Is there anyway to clear the navigation history?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

债姬 2024-12-24 09:45:44

您可以使用 NavigationService.RemoveBackEntry: http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.removebackentry%28v=VS.92%29.aspx

例如,删除堆栈中的所有条目:

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();
}

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();
}
肩上的翅膀 2024-12-24 09:45:44

虽然我知道最初的问题是针对 7 的,但在 Windows Phone 8.1 中,NavigationService 不再存在。

这是 Windows Phone 8.1 代码

 var previousPage = this.Frame.BackStack.FirstOrDefault();

 if (previousPage != null && previousPage.SourcePageType == typeof(MainPage))
 {
     this.Frame.BackStack.RemoveAt(this.Frame.BackStackDepth - 1);
 }

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);
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文