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

后端 未结 9 1212
暖寄归人
暖寄归人 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:10

    You need to create a ViewModel that has the concept of IsSelected on it and is bound to the IsSelected property of the actual ListBoxItem that represents it in the View using the standard WPF bindings architecture.

    Then in your code, which knows about your ViewModel, but not the fact that it's represented by any specific View, can just use that property to find out which items from the Model are actually selected irrespective of the designers choice for how its represented in the View.

提交回复
热议问题