How to add or remove an item from a CollectionView

2020-04-12 03:53发布

I want to bind a datagrid.itemsource to a List with anonymous type,so i bind it to a collectionViewSource,but i need to add or remove an item to the list,but i don't know how?

1条回答
你好瞎i
2楼-- · 2020-04-12 04:05

CollectionView and CollectionViewSource are, as their name suggest, only views. You can only manipulate the original collection. You should use an ObservableCollection if you want the changes to be automatically reflected in your UI.

I would advise against using anonymous types for data binding. But if you must - they implement the Equals method, so you should be able to remove items using new items with equal properties or using the item's index.

查看更多
登录 后发表回答