开发者

How do I write a linq query against a ListCollectionView?

开发者 https://www.devze.com 2023-03-08 11:07 出处:网络
none of these seem to do the tri开发者_如何转开发ck: var source = myViewModel.MyListCollectionView.Select(x => x as MyType);

none of these seem to do the tri开发者_如何转开发ck:

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);


ListCollectionView only implements the non-generic IEnumerable interface. I suspect you want:

var source = myViewModel.MyListCollectionView.Cast<MyType>();

or (if some values won't be of MyType, and that's okay):

var source = myViewModel.MyListCollectionView.OfType<MyType>();


var source = myViewModel.MyListCollectionView.OfType<MyType>();


The InternalList property is of type IList so you would be able to write a linq query against that.


ahhhh found it. you have to use Cast<> first!

var source = myViewModel.MyListCollectionView.Cast<MyType>().Select(p=>p.MyProperty);
0

精彩评论

暂无评论...
验证码 换一张
取 消