OnNavigatedTo不会导航到另一个页面 [英] OnNavigatedTo won't navigate to another page

查看:87
本文介绍了OnNavigatedTo不会导航到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在构建一个win 8 metro app c#/ XAML。我有一个用户访问的页面。如果满足条件,我希望它立即导航到另一个页面。


protected override void OnNavigatedTo(NavigationEventArgs e)

{

  ;           if(!App.AppSettings.IsConnectedToFacebook)

            {

                bool result = this.Frame.Navigate(typeof(LogInPage));

            }

}



但是,它不会导航到LogInPage。代码在我使用调试器逐步执行时执行,但不进行导航。 



任何人都可以帮忙吗?


谢谢

解决方案

这可能会让你走上正轨:


< pre class ="prettyprint"> protected override void OnNavigatedTo(NavigationEventArgs e)
{
if(ACondition)
{
this.Frame.NavigationStopped + = Frame_NavigationStopped;
this.Frame.StopLoading();
}
}

private void Frame_NavigationStopped(object sender,NavigationEventArgs e)
{
this.Frame.NavigationStopped - = Frame_NavigationStopped; //防止无限循环
this.Frame.Navigate(typeof(TheOtherPage));
}




Hi all,

I'm building a win 8 metro app c#/XAML. I have a page the user goes to. If a condition is met, I want it to immediately navigate to another page.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
            if (!App.AppSettings.IsConnectedToFacebook)
            {
                bool result = this.Frame.Navigate(typeof(LogInPage));
            }

}

However, it does not navigate to the LogInPage. The code executes as I step through it with the debugger, but no navigation takes place. 

Can anyone help?

Thanks

解决方案

This might get you on the right track:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    if (ACondition)
    {
        this.Frame.NavigationStopped += Frame_NavigationStopped;
        this.Frame.StopLoading();
    }
}

private void Frame_NavigationStopped(object sender, NavigationEventArgs e)
{
    this.Frame.NavigationStopped -= Frame_NavigationStopped; // Prevent infinite loop
    this.Frame.Navigate(typeof(TheOtherPage));
}



这篇关于OnNavigatedTo不会导航到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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