Windows Phone 8 Error with NavigationContext.QueryString.TryGetValue()

こ雲淡風輕ζ 提交于 2020-01-17 03:49:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!