WPF M-V-VM: Get selected items from a ListCollectionView?

后端 未结 9 1231
暖寄归人
暖寄归人 2020-12-09 17:33

I\'ve got a WPF app using the Model-View-ViewModel pattern.
In my ViewModel I\'ve got a ListCollectionView to keep a list of items.
This ListCollectionView is bound

9条回答
  •  一生所求
    2020-12-09 18:04

    Drew Marsh's answer is fine if you have a small list, if you have a large list the performance hit for finding all your selected items could be nasty! My favorite solution is to create an attached property on your ListBox that then binds to an ObservableCollection which contains your selected items. Then with your attached property you subscribe to the items SelectionChanged event to add/remove items from your collection.

提交回复
热议问题