我可以找出用户在 WP7 上按后退按钮来自哪个页面吗? [英] Can I find out which page a user came from on Back Button press on WP7?

查看:23
本文介绍了我可以找出用户在 WP7 上按后退按钮来自哪个页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过谷歌搜索找到答案的运气并不好,但是否可以判断用户来自哪个页面?

I haven't had much luck finding the answer through google searches, but is it possible to tell which page a user came from?

或者,在按下后退按钮时发送一个查询字符串,以便我知道?

Or, send a query string on back button press, so I can tell?

基本上,我有一个页面,我不希望用户通过按后退按钮进入该页面——他们应该到达那里的唯一方法是他们从一开始就遵循这个过程.我正在尝试做的一个很好的例子是不允许用户在他们已经成功注册后在注册帐户时返回确认设置.我宁愿他们去注册开始.

Basically, I have a page that I don't want a user to get to by pressing the back button -- the only way they should get there is if they followed the process from the start. A good example of what I'm trying to do is not allow a user to go back to the confirmation setup while registering for an account after they have already successfully registered. I'd rather them go to the start of registration.

推荐答案

您可以使用 NavigationService.BackStack 属性,并在导航到页面时检查返回堆栈中的第一个条目.

You can use the NavigationService.BackStack property and check the first entry in the back stack in the page as it is navigated to.

如果需要在多个页面中进行此检查,可以将其放入一个基类中.此外,如果您的情况符合@Skomski 提到的 eula/login 场景,那么他的回答最有意义.

If this check needs to be done in several pages, it could be put into a base class. Also, if your situation fits the eula/login scenario mentioned by @Skomski, his answer makes the most sense.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    var lastPage = NavigationService.BackStack.FirstOrDefault();

    if (lastPage != null && lastPage.Source.ToString() == "/MainPage.xaml")
    {
        NavigationService.RemoveBackEntry();
    }
}

这篇关于我可以找出用户在 WP7 上按后退按钮来自哪个页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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