处理listview窗口的项目点击

时间:2014-07-16 13:09:26

标签: c# json listview windows-phone-8.1

我使用c#

在windows 8.1 app中填写listview,如下所示
dynamic obj = JsonConvert.DeserializeObject(resp);

        List<Notice> items = new List<Notice>();

        foreach (var o in obj)
        {
            Notice notice = new Notice();
            items.Add(new Notice() { title = o["title"], from = o["from"] });
        }
        NoticeBinding.ItemsSource = items;
    }

    public class Notice
    {
        public string id { get; set; }
        public string title { get; set; }
        public string from { get; set; }
        public string sendername { get; set; }
        public string date { get; set; }
        public string content { get; set; }
    }

这给了我一个合适的listView。我想处理itemClick事件。对于相应的&#34; id&#34;在JSON响应中有一个&#34;标题&#34; ,&#34;内容&#34;和&#34;发件人&#34;通知。所以一旦我点击任何listview项目,应该显示相应的通知。以下是我的JSON响应的一部分

{
"id":20,
"title":"Testing after phase 2 is shifted to server",
"from":"Administrator",
"sendername":"ABX",
"day":"Tuesday",
"dateofMonth":"20th",
"month":"May",
"year":2014,
"date":"Tuesday, 20th May, 2014",
"content":"Ready. Set. Go"
}

在列表中仅查看&#34;标题&#34; &#34;来自&#34;显示。但点击后应显示标题,内容,发件人。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

IsItemClickEnabled属性设置为true,并在ItemClick中使用ListView点击事件。您可以通过访问其参数对象ItemClickEventArgs来访问被点击的项目,例如e.ClickedItem eItemClickEventArgs