充分利用的ListView在WinRT中选定的项目信息 [英] Getting Selected Item information from ListView in WinRT
本文介绍了充分利用的ListView在WinRT中选定的项目信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code这popualtes一个ListView与来自Flickr的照片
I have the following code which popualtes a ListView with photos from Flickr
private async void ParseFlickrResponse(HttpResponseMessage response)
{
XDocument xml = XDocument.Parse(await response.Content.ReadAsStringAsync());
var photos = from results in xml.Descendants("photo")
select new FlickrImage
{
ImageId = results.Attribute("id").Value.ToString(),
FarmId = results.Attribute("farm").Value.ToString(),
ServerId = results.Attribute("server").Value.ToString(),
Secret = results.Attribute("secret").Value.ToString(),
Title = results.Attribute("title").Value.ToString()
};
FlickrListView.ItemsSource = photos;
}
我希望能够再从该ListView中获取源数据的单个项目到其他地方使用。不过,我似乎无法与一些命令取得任何进展。我足够新的C#,我不知道我是否应该使用SelectedItems,项目或SelectedIndex的方法找出哪个节点我的照片存储在
I want to be able to then get source data for a individual item from this ListView to use elsewhere. However I can't seem to get anywhere with some of the commands. I'm new enough to C# and I don't know whether I should be using the SelectedItems, Items or SelectedIndex method to find which node my photo is stored in.
任何帮助将是巨大的。
推荐答案
您可以用这块code的:
You can use this piece of code:
编辑:与 SelectedItems
Dictionary<string, List<string>> dict =
FlickrListView.SelectedItems
.Cast<ListViewItem>()
.ToDictionary(
item => item.Text,
item => item.SubItems
.Cast<ListViewItem.ListViewSubItem>()
.Select(subItem => subItem.Text)
.ToList());
或
foreach (var item in FlickrListView.SelectedItems)
{
FlickrImage obj = (FlickrImage) item;
// ... do something ...
}
这篇关于充分利用的ListView在WinRT中选定的项目信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文