简体   繁体   中英

Windows Phone 8 navigation issue between pages

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));
    }

This works fine!

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));
    }

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

what am I not understanding here?

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

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

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));

            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM