views:

100

answers:

1

I'm just beginning to explore the M-V-VM design pattern while redeveloping an application and I'm running across a consistent theme where I have collections that I need my ViewModel to expose to the View which contain items which are to be selected by the user. Please note that when I say "selected" what I mean is that they are chosen in some permanent manner such as with check boxes within a grid control and not necessary highlighted like in a regular list box control. So far I have two different ideas of how this could be implemented and I want to know whether there are any thoughts about which way is the best to go about this.

  1. Expose two separate collections, one representing a read-only copy of available items and another which holds a subset of items which are contained within the first collection and represents those of the available items which are current selected.
  2. Expose a single collection through my ViewModel but make that collection a specialized collection that in some way tracks which items of the collection are selected. An example of this methodology can be found in this article by Josh Twist.

I do realize that option 2 is really just a modification of option 1 except for that the two collections are managed as one unit. I'm more interested knowing which ways have been proven successful in terms of manageability, performance, and effective data binding within WPF.

I've also come across an article on How to Databind to a SelectedItems property in WPF as well as another one which details how to Sync Multi Select Listbox with ViewModel. After reading the different methodologies out there I realize that this may not be something that M-V-VM practitioners have a reached a consensus on however I'm hoping I can limit the field a bit without trying each one and comparing.

A: 

This is a great article by Josh Smith on a similar subject.

kek444