我的代码:
ObservableCollection<SampleCheckedData> interestrates = new ObservableCollection<SampleCheckedData>();
XDocument xmlDocu = XDocument.Load(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(result)));
interestrates = (from rts in xmlDocu.Descendants("Friend")
select new SampleCheckedData
{
Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),
VisibleStatus = (string)rts.Element("visiblestatus"),
AppStatus = (string)rts.Element("loginstatus"),
imgBubble =bitmapRed,
}).ToList<SampleCheckedData>();
然后出现错误,因为不能像这样将 system.collection.generic.list 隐式转换为 system.collection.observablecollection。如何使用可观察集合绑定列表框项?
编辑:
Button b = sender as Button;
var res = interestrates.Where(a => a.Id.Equals(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag)).ToList();
if (res.Count == 1)
interestrates.Remove(res.First());
interestrates = new ObservableCollection<SampleCheckedData>();
lstFriendRequuest.ItemsSource = "";
bindGetFriends();
这里成功地从列表中删除项目,但是在调用 bindGetFriends() 新绑定项目之后,我没有得到新项目得到旧项目。为什么服务返回旧项目列表?