How to add or remove an item from a CollectionViewSource?

后端 未结 1 1627
你的背包
你的背包 2021-01-19 17:21

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 h

相关标签:
1条回答
  • 2021-01-19 18:02

    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.

    0 讨论(0)
提交回复
热议问题