问题描述
限时送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:关键词]
发布评论