HierarchicalDataTemplate Demo : HierarchicalDataTemplate « Windows Presentation Foundation « VB.Net Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="XML Data Binding">
  <Window.Resources>
    <HierarchicalDataTemplate DataType="Employees" ItemsSource="{Binding XPath=*}">
      <TextBlock FontStyle="Italic" Text="All Game Stats"/>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate DataType="Employee" ItemsSource="{Binding XPath=*}">
      <TextBlock FontWeight="Bold" FontSize="20" Text="{Binding XPath=@Type}"/>
    </HierarchicalDataTemplate>
    <DataTemplate DataType="YearOfWorking">
      <TextBlock Foreground="Blue" Text="{Binding XPath=.}"/>
    </DataTemplate>
    <XmlDataProvider x:Key="dataProvider" XPath="Employees">
      <x:XData>
        <Employees xmlns="">
          <Employee Type="Beginner">
            <YearOfWorking>1</YearOfWorking>
          </Employee>
          <Employee Type="Intermediate">
            <YearOfWorking>2</YearOfWorking>
          </Employee>
          <Employee Type="Advanced">
            <YearOfWorking>3</YearOfWorking>
          </Employee>
        </Employees>
      </x:XData>
    </XmlDataProvider>
  </Window.Resources>
  <Grid>
    <TreeView ItemsSource="{Binding Source={StaticResource dataProvider},XPath=.}" />
  </Grid>
</Window>
WPF Hierarchical Data Template








16.98.HierarchicalDataTemplate
16.98.1.HierarchicalDataTemplate DemoHierarchicalDataTemplate Demo