页面之间的Windows Phone 8导航问题 [英] Windows Phone 8 navigation issue between pages

查看:62
本文介绍了页面之间的Windows Phone 8导航问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有登录过程的Windows Phone应用程序,该登录过程访问外部API. 登录按钮的控制器最初运行了一些代码,这些代码可立即导航到仪表板页面:

I have a windows phone app with a login process, that login process accesses an external API. The controller for the login button originally ran some code that instantly navigated to the dashboard page:

    private void LogInButton_Click(object sender, RoutedEventArgs e)
    {
        ...

        App.RootFrame.Navigate(new Uri("/Interface.xaml", UriKind.RelativeOrAbsolute));
    }

这很好!

稍后,我认为最好实现与api的实际连接,检查用户详细信息是否正确,然后重定向到仪表板.为了简洁起见,我已经删除了api的各个部分,但可以说此函数作为 Action委托在整个地方传递,然后再在正确的位置(即控制器)被调用.

Later on, I thought it best to implement the actual connection to the api, check if the user details are correct and on that, redirect to the dashboard. for brevity I have taken out the api parts, but let's say this function gets passed all over the place as an Action delegate before being called in it's rightful place, the controller..

    ...
    // This method is also located in the controller class, but it is called by another class
    public void LoadDashboard( DataUpdateState data )
    {
        //data.AsyncResponse
        App.RootFrame.Navigate(new Uri("/Interface.xaml", UriKind.RelativeOrAbsolute));
    }

问题是,导航方法现在不再起作用,它会在RootFrame_NavigationFailed上触发调试中断.

The thing is, the navigation method now no longer works, it fires a debug break on RootFrame_NavigationFailed.

我在这里不明白什么?

有没有办法找出为什么在App类中加载了导航失败的方法

Is there a way of finding out just why it loaded the navigation failed method in the App class

推荐答案

您可以在导航失败事件的NavigationFailedEventArgs中(在Exception参数中)获得更多详细信息.

You can get more detail in the NavigationFailedEventArgs of the navigation failed event (in the Exception parameter).

最可能的原因是您尝试从非ui线程调用Navigate.如果是这种情况,请使用调度程序在ui线程上进行调度:

The most probable cause is that you are try to call Navigate from a non ui thread. If that the case just use a dispatcher to dispatch it on the ui thread:

Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
        App.RootFrame.Navigate(new Uri("/Interface.xaml", UriKind.RelativeOrAbsolute));

            });

这篇关于页面之间的Windows Phone 8导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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