Is it possible and if so what is the best way to implement the following hierarchical structure in a silverlight (4) TreeView control? (where Item and Group are classes which can exist in the tree).
Group
|
|-Item
|
|-Group
| |
| |-Item
| |
| |-Item
|
|-Item
The structure could of course be arbitrarily more complex than this, if needed.
HierarchicalDataTemplates appear to be the way to approach this, but I'm specifically having trouble understanding how I might apply the template to interpret the different classes correctly.
A similar question was asked for WPF, the answer for which made use of the TargetType property on the HierarchicalDataTemplate, but I am uncertain whether that property is available in the silverlight version since I don't appear to have access to it in my environment.
My implementation
MainClass
Converter
I plan to add the Field display types DateTime, Bool, ...
For Silverlight, you might need to create a converter to help do this. For instance, a "target type data template selector" or similar.
Though you could get more advanced, here is an example from the Silverlight unit test framework that allows you to provide instances of data templates for hard-coded types. A generalized version could probably be made in about 20 minutes.
To use this, you'd provide instances of data templates - in your case though, you'd probably need to make them hierarchical.
And here is the implementation: