从导航日志中删除 2 个条目 [英] Remove 2 Entries from Navigation Journal

查看:23
本文介绍了从导航日志中删除 2 个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 windows phone 8 应用程序中,我必须在导航到不同页面之前检查用户是否已经登录.如果用户未登录,我会将用户导航到 Login.xaml,从中用户可以选择从 Facebook 或 Twitter 登录或取消.

In my windows phone 8 app i have to check if user is already login or not before navigating to different pages. If user is not logged in i navigate the user to Login.xaml from where user chooses either login from Facebook or twitter or cancel.

现在,当用户成功登录时,我会将用户导航到适当的页面.我的问题是如何删除那些潜在的 2 个页面(login.xaml 和 facebook/twitter 登录)?

Now when user successfully logs in i navigate the user to appropriate page. My question is how to remove those potential 2 pages (login.xaml and facebook/twitter login)?

NavigationService.BackStack is IEnumerable :(

有人可以解决吗?

推荐答案

如果和使用 WPF NavigationService 一样,那么你可以使用 RemoveBackEntry 导航到新页面后.

If it is the same as using the WPF NavigationService then you can use RemoveBackEntry after you have navigated to the new page.

更新:

如果您使用诸如

if (!user.IsLoggedIn)
{
  NavigationService.Navigate(new Login());
}

然后你可以在任何人有机会看到它们之前删除后面的条目

Then you can remove the back entries before anyone has a chance to see them

if (!user.IsLoggedIn)
{
  NavigationService.Navigate(new Login());
  //Hide back entry
  NavigationService.RemoveBackEntry();
}

但是,如果您无法执行此操作,例如当您最终在返回条目中包含 Facebook/twitter 网址时,请改为订阅 导航事件,然后删除它们

However if you are unable to do this, for example when you end up with a Facebook/twitter url in the back entry, then instead subscribe to the Navigated event and then remove them

public Login()
{
   NavigationService.Navigated += HideEntriesOnNavigated;
}

void HideEntriesOnNavigated(object sender, NavigationEventArgs e)
{
  if (IsFacebookLogin(e.Url)
    || IsTwitterLogin(e.Url)
    || IsAppLoginPage(e.Url))
  {
     NavigationService.RemoveBackEntry();
  }
}

这篇关于从导航日志中删除 2 个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆