HierarchicalDataTemplate Class
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
'Declaration Public Class HierarchicalDataTemplate Inherits DataTemplate 'Usage Dim instance As HierarchicalDataTemplate
public class HierarchicalDataTemplate extends DataTemplate
public class HierarchicalDataTemplate extends DataTemplate
<HierarchicalDataTemplate> VisualTree </HierarchicalDataTemplate>
In the following example, ListLeagueList is a list of League objects. Each League object has a Name and a collection of Division objects. Each Division has a Name and a collection of Team objects, and each Team object has a Name.
<Window x:Class="SDKSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="HierarchicalDataTemplate Sample" xmlns:src="clr-namespace:SDKSample"> <DockPanel> <DockPanel.Resources> <src:ListLeagueList x:Key="MyList"/> <HierarchicalDataTemplate DataType = "{x:Type src:League}" ItemsSource = "{Binding Path=Divisions}"> <TextBlock Text="{Binding Path=Name}"/> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType = "{x:Type src:Division}" ItemsSource = "{Binding Path=Teams}"> <TextBlock Text="{Binding Path=Name}"/> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type src:Team}"> <TextBlock Text="{Binding Path=Name}"/> </DataTemplate> </DockPanel.Resources> <Menu Name="menu1" DockPanel.Dock="Top" Margin="10,10,10,10"> <MenuItem Header="My Soccer Leagues" ItemsSource="{Binding Source={StaticResource MyList}}" /> </Menu> <TreeView> <TreeViewItem ItemsSource="{Binding Source={StaticResource MyList}}" Header="My Soccer Leagues" /> </TreeView> </DockPanel> </Window>
The example shows that with the use of HierarchicalDataTemplate, you can easily display list data that contains other lists. The following is a screenshot of the example.
For the complete sample, see Displaying Hierarchical Data Sample.
More Code
| How to: Create Simple or Complex TreeViews | This example shows how to create simple or complex TreeView controls. |
| How to: Use SelectedValue, SelectedValuePath, and SelectedItem | This example shows how to use the SelectedValue and SelectedValuePath properties to specify a value for the SelectedItem of a TreeView. |
System.Windows.Threading.DispatcherObject
System.Windows.FrameworkTemplate
System.Windows.DataTemplate
System.Windows.HierarchicalDataTemplate
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.