How to implement Master-Detail with Multi-Selection in WPF?

Posted by gehho on Stack Overflow See other posts from Stack Overflow or by gehho
Published on 2010-03-18T09:38:15Z Indexed on 2010/03/18 9:41 UTC
Read the original article Hit count: 411

Hi,

I plan to create a typical Master-Detail scenario, i.e. a collection of items displayed in a ListView via DataBinding to an ICollectionView, and details about the selected item in a separate group of controls (TextBoxes, NumUpDowns...).

No problem so far, actually I have already implemented a pretty similar scenario in an older project. However, it should be possible to select multiple items in the ListView and get the appropriate shared values displayed in the detail view. This means, if all selected items have the same value for a property, this value should be displayed in the detail view. If they do not share the same value, the corresponding control should provide some visual clue for the user indicating this, and no value should be displayed (or an "undefined" state in a CheckBox for example). Now, if the user edits the value, this change should be applied to all selected items.

Further requirements are:

  • MVVM compatibility (i.e. not too much code-behind)
  • Extendability (new properties/types can be added later on)

Does anyone have experience with such a scenario? Actually, I think this should be a very common scenario. However, I could not find any details on that topic anywhere.

Thanks!
gehho.

PS: In the older project mentioned above, I had a solution using a subclass of the ViewModel which handles the special case of multi-selection. It checked all selected items for equality and returned the appropriate values. However, this approach had some drawbacks and somehow seemed like a hack because (besides other smelly things) it was necessary to break the synchronization between the ListView and the detail view and handle it manually.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about multiselect