清除 NavigationService 中的 backstack

编程入门 行业动态 更新时间:2024-10-27 01:35:01
本文介绍了清除 NavigationService 中的 backstack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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?

推荐答案

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

You can use NavigationService.RemoveBackEntry: http://msdn.microsoft/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();
}


此外,如果您想在检查其 URI 后仅删除上一页:


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

这篇关于清除 NavigationService 中的 backstack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 15:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NavigationService   backstack

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!