C# 列表框选择更改WP7以使用参数导航

C# 列表框选择更改WP7以使用参数导航,c#,json,windows-phone-7,xaml,listbox,C#,Json,Windows Phone 7,Xaml,Listbox,因此,在我正在制作的WindowsPhone7应用程序中,我使用一个带有SelectionChanged事件处理程序的列表框将用户导航到一个新网页,显示其他信息。xaml显示了一个列表框,其中填充了JSON文件中的信息,该文件工作正常。但是,如果用户想阅读更多有关新闻的信息,他/她必须单击列表框中的新闻,这将触发SelectionChanged事件,如下所示: private void NewsList_SelectionChanged_1(object sender, Selectio

因此,在我正在制作的WindowsPhone7应用程序中,我使用一个带有SelectionChanged事件处理程序的列表框将用户导航到一个新网页,显示其他信息。xaml显示了一个列表框,其中填充了JSON文件中的信息,该文件工作正常。但是,如果用户想阅读更多有关新闻的信息,他/她必须单击列表框中的新闻,这将触发SelectionChanged事件,如下所示:

    private void NewsList_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
    {
        int index = NewsList.SelectedIndex;

        fetchNewsContent newsContentGetSet = new fetchNewsContent();

        newsContentGetSet.newsID = newslistJson.ElementAt(index).news_id;
        newsContentGetSet.newsTitle = newslistJson.ElementAt(index).news_title;
        newsContentGetSet.newsAbstract = newslistJson.ElementAt(index).news_abstract;
        newsContentGetSet.newsContent = newslistJson.ElementAt(index).news_content;
        newsContentGetSet.newsAuthor = newslistJson.ElementAt(index).news_author;
        newsContentGetSet.newsDatePublished = newslistJson.ElementAt(index).news_date_published_no;

        //object[] someobject = { newsContentGetSet.newsID, newsContentGetSet.newsTitle, newsContentGetSet.newsAbstract, newsContentGetSet.newsContent, newsContentGetSet.newsAuthor, newsContentGetSet.newsDatePublished };

        NavigationService.Navigate(new Uri("/NewsPage.xaml?obj=" + index, UriKind.Relative));

    }
这只是使用一个类(newsContentGetSet.cs),每个字符串(newsID、newsTitle等)都有getter和setter,但是当触发SelectionChanged时,.cs文件不会设置新给定的newslistJson值!为什么?

我还尝试在NavigationService中只发送文本参数,但newsContent字符串太长(整个新闻故事),因此它返回了一个“shell page uri太长”错误


现在,这只是将索引int发送到NewsPage页面,该页面尝试捕获值,但失败了,因为newsContentGetSet实际上没有设置任何内容(尝试时不会调试到其中)。有什么想法吗,真的

而不是在参数上传递数据。您应该将数据保存到App类中的变量中,然后在导航到下一页时从该类中检索数据

App.xaml.cs

public static fetchNewsContent newsContentGetSet;
访问它

var fetchedNewsContent = App.fetchNewsContent;

您可以从任何页面存储/检索数据。请注意,如果应用程序关闭,数据将丢失。

有效!你又一次精彩的扑救。谢谢