TreeView.ItemContainerStyle Property


Gets or sets the Style that is applied to the container element generated for each item.

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

public Style ItemContainerStyle { get; set; }
</sdk:TreeView >
<sdk:TreeView ItemContainerStyle="{StaticResource resourceReferenceToStyle}"/>

XAML Values


A single Style object element. For a TreeView instance, the style is expected to target and template TreeViewItem.


A resource reference to an existing Style from a resources collection.

Property Value

Type: System.Windows.Style
The Style applied to the container element that contains each item.

Dependency property identifier field: ItemContainerStyleProperty

This style is applied to the TreeViewItem or other container used in a derived class.

The following example shows how to create a custom style as a resource and set the ItemContainerStyle property to the custom style.

Run this sample

  <Grid x:Name="LayoutRoot" Background="White">
          <Style  x:Key="myTVIStyle" TargetType="sdk:TreeViewItem">
              <Setter Property="Background" Value="Khaki" />
              <Setter Property="Foreground" Value="DarkSlateGray" />
              <Setter Property="Margin" Value="5" />
              <Setter Property="FontStyle" Value="Italic" />
              <Setter Property="FontSize" Value="14" />
              <Setter Property="BorderBrush" Value="DarkGray" />
<sdk:TreeView ItemContainerStyle="{StaticResource myTVIStyle}">
          <sdk:TreeViewItem Header="Item1" />
          <sdk:TreeViewItem Header="Item2" />
          <sdk:TreeViewItem Header="Item3" />


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions