这些似乎没有做到这一点:
var source = myViewModel.MyListCollectionView.Select(x => x as MyType);
var source = myViewModel.MyListCollectionView.Select<object, MyType>(x => x as MyType);
var source = myViewModel.MyListCollectionView.SourceCollection.Select<object, MyType>(x => x as MyType);
答案 0 :(得分:26)
ListCollectionView
仅实现非通用IEnumerable
接口。我怀疑你想要:
var source = myViewModel.MyListCollectionView.Cast<MyType>();
或(如果某些值不是MyType
,那没关系):
var source = myViewModel.MyListCollectionView.OfType<MyType>();
答案 1 :(得分:7)
var source = myViewModel.MyListCollectionView.OfType<MyType>();
答案 2 :(得分:2)
InternalList
属性的类型为IList
,因此您可以针对该属性编写linq
查询。
答案 3 :(得分:1)
var source = myViewModel.MyListCollectionView.Cast<MyType>().Select(p=>p.MyProperty);