ItemsSource Property

HierarchicalDataTemplate::ItemsSource Property


Gets or sets the binding for this data template, which indicates where to find the collection that represents the next level in the data hierarchy.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

property BindingBase^ ItemsSource {
	BindingBase^ get();
	void set(BindingBase^ value);

Property Value

Type: System.Windows.Data::BindingBase^

The default is null.

This is applied to the ItemsSource property on a generated HeaderedItemsControl (such as a MenuItem or a TreeViewItem) to indicate where to find the collection that represents the next level in the data hierarchy.

For XAML information, see the Binding type.

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"
  Title="HierarchicalDataTemplate Sample"
      <src:ListLeagueList x:Key="MyList"/>

      <HierarchicalDataTemplate DataType    = "{x:Type src:League}"
                                ItemsSource = "{Binding Path=Divisions}">
        <TextBlock Text="{Binding Path=Name}"/>

      <HierarchicalDataTemplate DataType    = "{x:Type src:Division}"
                                ItemsSource = "{Binding Path=Teams}">
        <TextBlock Text="{Binding Path=Name}"/>

      <DataTemplate DataType="{x:Type src:Team}">
        <TextBlock Text="{Binding Path=Name}"/>

    <Menu Name="menu1" DockPanel.Dock="Top" Margin="10,10,10,10">
        <MenuItem Header="My Soccer Leagues"
                  ItemsSource="{Binding Source={StaticResource MyList}}" />

      <TreeViewItem ItemsSource="{Binding Source={StaticResource MyList}}" Header="My Soccer Leagues" />


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.

HierarchicalDataTemplate sample screen shot

.NET Framework
Available since 3.0
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft