WPF treeview: "non listed items"

65 Views Asked by At

based on my model I want to build a treeview. For me it turns out to be a problem, that only members of a collection can be displayed In a treeview. That means, that I have to create a viewmodel containing a collection which holds all properties of my model.

I want to build a tree like this:

House
  Adress
  Color
  NumberOfRooms
  Family
   Father
   Mother
   Daughter
    Age
    Hair color
    Friends
     ...
  Pets
   Dog
   Mouse

My house model has the property adress, color, numberOfRooms, family and pets. Not all of the are lists, and house itself isnt a list either. So i would have to put those properties in a list of objects to be displayed in a tree like fashion, and then create a hierachical datatemplate for each of those properties. Doing this once is not a big deal, but I have many models to deal with, this just doesnt seem to be the right way...

I know i could make a hierachical datatemplate for the House type, put "house" in the header of an expander, and add some textboxes for each non list list property ... This is just ugly.

Is there any common approach for this kind of datastructure / model ?

1

There are 1 best solutions below

0
On

It turns out that using MultiBinding + Converter is a pretty elegant solution.

Here is a link http://www.hardcodet.net/2008/12/heterogeneous-wpf-treeview