Windows Phone 8 页面之间的导航问题

Windows Phone 8 navigation issue between pages(Windows Phone 8 页面之间的导航问题)
本文介绍了Windows Phone 8 页面之间的导航问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个带有登录过程的 Windows 手机应用程序,该登录过程访问外部 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 页面之间的导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)