如何重定向到另一个xaml页面windows phone c#

如何重定向到另一个xaml页面windows phone c#,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我有以下代码,可以确定发布请求(到外部api)的状态是否成功,如果成功,它应该导航到我在windows phone应用程序中创建的Interface.xaml页面。不确定哪个类处理xaml页面之间的导航 public bool UsernameAndPassword(string username, string password) { data = "grant_type=" + GRANTTYPE + "&username=" + username + "&passw

我有以下代码,可以确定发布请求(到外部api)的状态是否成功,如果成功,它应该导航到我在windows phone应用程序中创建的Interface.xaml页面。不确定哪个类处理xaml页面之间的导航

public bool UsernameAndPassword(string username, string password)
{
    data = "grant_type=" + GRANTTYPE + "&username=" + username + "&password=" + password + "&client_id=" + CLIENTID + "&redirect_uri=" + REDIRECTURI + "&client_secret=" + CLIENTSECRET;
    return true;
}

public bool Authenticate()
{
    // form the URI
    UriBuilder fullUri = new UriBuilder(urlPath);
    fullUri.Query = data;

    // initialize a new WebRequest
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
    request.Method = "POST";

    // set up the state object for the async request
    DataUpdateState dataState = new DataUpdateState();
    dataState.AsyncRequest = request;

    // start the asynchronous request
    request.BeginGetResponse(new AsyncCallback(HandleResponse),
        dataState);

    return true;
}

private void HandleResponse(IAsyncResult asyncResult)
{
    // get the state information
    DataUpdateState dataState = (DataUpdateState)asyncResult.AsyncState;
    HttpWebRequest dataRequest = (HttpWebRequest)dataState.AsyncRequest;

    // end the async request
    dataState.AsyncResponse = (HttpWebResponse)dataRequest.EndGetResponse(asyncResult);
    if (dataState.AsyncResponse.StatusCode.ToString() == "OK")
    {
        // What needs to go here to navigate to another xaml page?
        // something like this? - NavigationService.Navigate(new Uri("Interface.xaml", UriKind.Relative));    
    }

}

public class DataUpdateState
{
    public HttpWebRequest AsyncRequest { get; set; }
    public HttpWebResponse AsyncResponse { get; set; }
}
可以在if语句的HandleResponse方法中找到问题

//编辑::

我现在扩展了PhoneApplicationPage类,该类允许我访问NavigationService。。。但是,当我现在执行程序时,当我使用以下命令导航到新页面时:

NavigationService.Navigate(new Uri("Interface.xaml", UriKind.Relative));
它抛出一个运行时错误:

An exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll but was not handled in user code

If there is a handler for this exception, the program may be safely continued.

有什么想法吗?

在我参与的一个Windows Phone项目中,我们在基本视图模型上设置了一个方法,该方法将发布一个事件,并在App.xaml.cs中进行如下处理:

Messenger.Default.Register<NavigateMessage>(this, (navigateMessage) =>
{
  Deployment.Current.Dispatcher.BeginInvoke(() =>
  {
    ApplicationParameter = navigateMessage.Parameter;
    RootFrame.Navigate(navigateMessage.Destination);
  });
});
Messenger.Default.Register(此,(导航消息)=>
{
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
ApplicationParameter=navigateMessage.Parameter;
RootFrame.Navigate(navigateMessage.Destination);
});
});
目标是视图的URI。我们将导航参数存储在一个公共区域中,因为您只能在本地以字符串的形式传递查询参数


App.xaml.cs包含我们用于导航的RootFrame元素。因此,我认为您要寻找的关键部分是根框架。导航

在我参与的一个Windows Phone项目中,我们在基本视图模型上设置了一个方法,该方法将发布事件,并在App.xaml.cs中像这样处理:

Messenger.Default.Register<NavigateMessage>(this, (navigateMessage) =>
{
  Deployment.Current.Dispatcher.BeginInvoke(() =>
  {
    ApplicationParameter = navigateMessage.Parameter;
    RootFrame.Navigate(navigateMessage.Destination);
  });
});
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/UserDetail.xaml", UriKind.Relative));
Messenger.Default.Register(此,(导航消息)=>
{
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
ApplicationParameter=navigateMessage.Parameter;
RootFrame.Navigate(navigateMessage.Destination);
});
});
目标是视图的URI。我们将导航参数存储在一个公共区域中,因为您只能在本地以字符串的形式传递查询参数

App.xaml.cs包含我们用于导航的RootFrame元素。因此,我认为您要寻找的关键部分是
RootFrame.Navigate

(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/UserDetail.xaml", UriKind.Relative));
试试这个


试试这个

根框架的用途是什么?在msdn上找不到它?不是system.windows之类的东西,是吗?啊,找到了,你必须扩展:PhoneApplicationPage我刚才找到它的方式是通过App.RootFrame。这可能不是最佳实践,但调用
App.RootFrame.Navigate(新Uri(“/Page2.xaml”,UriKind.RelativeOrAbsolute))工作。这是因为我在一个外部文件中试图调用它,但是我重新工作了它,以便我的控制器进行导航,这更有意义。。因此问题得以避免:)谢谢!RootFrame的用途是什么?在msdn上找不到它?不是system.windows之类的东西,是吗?啊,找到了,你必须扩展:PhoneApplicationPage我刚才找到它的方式是通过App.RootFrame。这可能不是最佳实践,但调用
App.RootFrame.Navigate(新Uri(“/Page2.xaml”,UriKind.RelativeOrAbsolute))工作。这是因为我在一个外部文件中试图调用它,但是我重新工作了它,以便我的控制器进行导航,这更有意义。。因此问题得以避免:)谢谢!