TreeView.ItemContainerStyle Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Property ItemContainerStyle As Style
public Style ItemContainerStyle { get; set; }
<sdk:TreeView>
  <sdk:TreeView.ItemContainerStyle>
    inlineStyle
  </sdk:TreeView.ItemContainerStyle>
</sdk:TreeView >
<sdk:TreeView ItemContainerStyle="{StaticResource resourceReferenceToStyle}"/>

XAML Values

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

  • resourceReferenceToStyle
    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.

Remarks

Dependency property identifier field: ItemContainerStyleProperty

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

Examples

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">
      <Grid.Resources>
          <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" />
          </Style>
        </Grid.Resources>
<sdk:TreeView ItemContainerStyle="{StaticResource myTVIStyle}">
          <sdk:TreeViewItem Header="Item1" />
          <sdk:TreeViewItem Header="Item2" />
          <sdk:TreeViewItem Header="Item3" />
      </sdk:TreeView>
  </Grid>

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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