Lets say I have the following data:
<XmlDataProvider x:Key="Values">
<x:XData>
<folder name="C:">
<folder name="stuff" />
<folder name="things" />
<folder name="windows">
<folder name="system32" />
</folder>
</folder>
</x:XData>
</XmlDataProvider>
How can I get that into a treeview? I can’t seem to grok hierarchical binding…
I know that I can get it in there in C# code, but I wanted to do it with a binding expression.
EDIT: Didn’t see that you wanted to do this in XAML only. This MSDN post should help you out.
HierarchicalDataTemplateisn’t so bad if your data is already in a hierarchical form. Let’s say you translate that XML data into a model class using code like this:Then the XAML for your
TreeViewwould be as simple as this:And the result:
alt text http://img191.imageshack.us/img191/7841/treeviewhierarchy.png