3 回答
TA贡献1836条经验 获得超3个赞
正如 JH 建议的那样,解决方案是 SelectedItem 而不是 Selectedindex,
结果代码是:
private void albums_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = albums.SelectedIndex;
if (index >= 0)
{
int indexid = albums.SelectedIndex;
var selectedObject = albums.SelectedItems[0] as Albumclass.Albumlist2;
if (selectedObject == null)
{
return;
}
id = selectedObject.Id;
//obteniendo lista de albums
string tagurl = "http://" + serverurl + "/server/xml.server.php?action=album_songs&auth=" + token + "&filter=" + id;
string[] tagarray = { tagurl, "song", "track", "title", "composer", "artist", "time", "tag", "comment", "url" };//Creando array con datos a utilizar
//Lennado ListView Songs
Songs.ItemsSource = null;
songs = new ObservableCollection<Albumclass.Albumlist2>();
songs = xmlobserv.Xmlparser(tagarray);
Songs.ItemsSource = songs;
}
}
当我重置gridview时,我只使用selectedIndex来避免错误
非常感谢
TA贡献1815条经验 获得超10个赞
检查SelectionChangedEventArgs参数,它包含您的信息。
private void albums_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//if the listview doesn't allow multi-selection,
//then this list contains only one item
foreach (object o in e.AddedItems)
{
Album al = o as Album;
id = al.Id;
//...
}
}
TA贡献1811条经验 获得超5个赞
您是否尝试过类似的方法:
ObservableCollection<Albumclass.Albumlist2> _collection = new ObservableCollection<Albumclass.Albumlist2>(); _collection.IndexOf(_item)
这是文档http://msdn.microsoft.com/en-us/library/ms132410.aspx
- 3 回答
- 0 关注
- 109 浏览
添加回答
举报