编辑:以下代码有效!(我注释掉,构建,然后取消注释并且它起作用了)。
我有ObservableCollection
一个ListBox
. 我想仅根据显示名称选择其中一些项目,因为我不知道项目值。但是我得到一个转换错误(IEnumerable 到 ObservableCollection)。
ObservableCollection<ListBoxItem> unselectedcollection
= new ObservableCollection<ListBoxItem>
(dt.AsEnumerable()
.Select(i => new ListBoxItem(i[ColumnNames.LISTNAMECOL].ToString(),
i[ColumnNames.LISTVALUECOL].ToString())));
ObservableCollection<ListBoxItem> selectedcollection
= new ObservableCollection<ListBoxItem>
(from item in unselectedcollection.AsEnumerable()
where (item.Name == "firstName"
|| item.Name == "secondName"
|| item.Name == "thirdName")
select item);
我已经尝试了我能想到的各种铸造选项。我错过了什么?