我有从 Flickrs Rest 服务中获取数据并填充 ListView 的代码。此代码工作正常,当我运行我的应用程序时,我可以搜索照片并显示它们的列表。但是,我想然后获取单个照片数据,但是当我尝试从 ListView 访问此数据时,它完全是空的(我已对其进行了调试,并且仅包含空条目)。我在 C# 方面没有很多经验,所以无论如何都可以告诉我为什么我会得到空结果?
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;
}
已编辑
当前代码:
enter code here:
私有异步无效 ParseFlickrResponse(HttpResponseMessage 响应){
XDocument xml = XDocument.Parse(await response.Content.ReadAsStringAsync());
var photos = from results in xml.Descendants("photo").ToList()
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 = new ObservableCollection<FlickrImage>(photos);
}
private void GetPhotoSource(object sender, ItemClickEventArgs e)
{
int inx = FlickrListView.SelectedIndex;
// FlickrImage t = lst.First();
FlickrImage t = lst.ElementAt(inx);
MyImage.Source = new BitmapImage(new Uri(t.ImageUrl.ToString(), UriKind.Absolute));
}