問題描述
我有一個帶有登錄過程的 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 頁面之間的導航問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!