How to redirect to another xaml page windows phone c#
I have the following code that finds out if the status of the posted
request (to an external api) was successful, and if so, it should navigate
to the Interface.xaml page I have created in the windows phone app.
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")
{
// Navigatge to Interface.xaml not working?
NavigationService.Navigate(new Uri("Interface.xaml",
UriKind.Relative));
}
}
The problem can be found within the HandleResponse method in the if
statement.
public class DataUpdateState
{
public HttpWebRequest AsyncRequest { get; set; }
public HttpWebResponse AsyncResponse { get; set; }
}
No comments:
Post a Comment