views:

7

answers:

0

Hi,

I'd like to visualize XML data with the WPF TreeView control. The treeview displays all elements of the XML data in hierarchical order. Below the treeview is a ListBox containing TextBoxes for editing the name, the value of the element and all its attributes.

I have figured out how to display the XML data in the treeview. But I don't have an idea how to bind the textboxes to the selected element in the treeview:

<UserControl.Resources>
  <HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}" x:Key="TVTemplate">
   <TreeViewItem Header="{Binding Path=Name}"/>
  </HierarchicalDataTemplate>
 </UserControl.Resources>

 <StackPanel>
  <TreeView x:Name="TreeView" ItemsSource="{Binding Path=Root.Elements}" ItemTemplate="{StaticResource TVTemplate}" SelectedValuePath="Attributes" >
  </TreeView>


  <ListView ItemsSource="{Binding ElementName=TreeView, Path=SelectedValuePath}">
   <ListView.View>
    <GridView AllowsColumnReorder="False" ColumnHeaderToolTip="Element Information">
     <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Name" Width="Auto"/>
     <GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Value" Width="Auto" />
    </GridView>
   </ListView.View>
  </ListView>
 </StackPanel>

What can I do to let the GridView show the attributes' names and values?