5

I'm not sure how to approach this: I want a TreeView that will display some simple data from a hierarchical data structure. As a basic example (In XML, cause it's easy to type):

<Node text="Root">
    <Node text="Item 1">
        <Node text="Item 1.1" />
    </Node>
    <Node text="Item 2"/>
</Node>

The catch is that this could theoretically nest infinitely deep, so you can't statically define x number of levels and be done with it. Is there a way to define a HierarchicalDataTemplate that can account for this kind of structure?

Toji
  • 33,927
  • 22
  • 105
  • 115

1 Answers1

11

HeirarchicalDataTemplate is used exactly to solve this kind of issue. You can just use a simple template like bellow to achieve this.

  <HierarchicalDataTemplate DataType="Node" ItemsSource ="{Binding XPath=*}">
        <TextBlock Text="{Binding XPath=@text}" />
    </HierarchicalDataTemplate>
Jobi Joy
  • 49,102
  • 20
  • 108
  • 119
  • Sorry for the delay in marking this answered. Didn't have time to verify it until just now. Figures that it would be something uber simple :) Thanks! – Toji Nov 24 '08 at 01:25