我有以下代码可以确定发布的请求(到外部 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.
有任何想法吗?