Silverlight recursivly bind Treeview to XDocument

Posted by Michael Wagner on Stack Overflow See other posts from Stack Overflow or by Michael Wagner
Published on 2010-04-18T11:33:18Z Indexed on 2010/04/18 11:43 UTC
Read the original article Hit count: 1255

How can I recursivly bind a Treeview to an XDocument, mapping each XML Element to a Node in the Treeview?

The code below should work from my perspective (and also according to the very few posts I found regarding direct binding), however it does not:

<sdk:TreeView ItemsSource="{Binding Path=Elements}" DataContext="{Binding Path=Data}">
  <sdk:TreeView.ItemTemplate>
   <data:HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}">
    <StackPanel Orientation="Vertical">
     <TextBlock Text="{Binding Name}"/>
    </StackPanel>
   </data:HierarchicalDataTemplate>
  </sdk:TreeView.ItemTemplate>
</sdk:Treeview>

(Data is a Property of type XElement on the parents' DataContext)

Did I make a mistake somewhere or do I really need to implement an IValueConverter just to get at the child elements of an XElement?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about treeview