问题
I've run into an issue with passing parameters between pages. OnNavigatedTo is definitely being called but the if statement keeps returning false, when it should return true. Can anyone out there shoot me in the right direction?
The following is on my main page:
NavigationService.Navigate(new Uri("/Class_page.xaml?name=" + classes[0].name
+ "&code=" + classes[0].code + "&semester=" + classes[0].semester
+ "&index=" + index, UriKind.Relative));
The following is on my "Class_page":
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string cn, cc, sm, i, grd, oo, wg;
if (NavigationContext.QueryString.TryGetValue("name=", out cn) &&
NavigationContext.QueryString.TryGetValue("code=", out cc) &&
NavigationContext.QueryString.TryGetValue("semester=", out sm) &&
NavigationContext.QueryString.TryGetValue("index=", out i) )
{
/*it never reaches this point*/
NavigationService.Navigate(new Uri("/test_page.xaml", UriKind.Relative));
curr = Convert.ToInt32(i);
grades[curr] = new class_gds(cn, cc, sm); //adds course to array
class_name.Text = grades[curr].GetName();
class_code.Text = grades[curr].GetCode();
semester.Text = grades[curr].GetSemester();
}
回答1:
Change this:
if (NavigationContext.QueryString.TryGetValue("name=", out cn) &&
NavigationContext.QueryString.TryGetValue("code=", out cc) &&
NavigationContext.QueryString.TryGetValue("semester=", out sm) &&
NavigationContext.QueryString.TryGetValue("index=", out i)
To this:
if (NavigationContext.QueryString.TryGetValue("name", out cn) &&
NavigationContext.QueryString.TryGetValue("code", out cc) &&
NavigationContext.QueryString.TryGetValue("semester", out sm) &&
NavigationContext.QueryString.TryGetValue("index", out i)
来源:https://stackoverflow.com/questions/25633409/windows-phone-8-error-with-navigationcontext-querystring-trygetvalue