Export (0) Print
Expand All

TreeViewItem Class

Implements a selectable item in a TreeView control.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[TemplatePartAttribute(Name="PART_Header", Type=typeof(FrameworkElement))] 
[StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=typeof(TreeViewItem))] 
public class TreeViewItem : HeaderedItemsControl
/** @attribute TemplatePartAttribute(Name="PART_Header", Type=System.Windows.FrameworkElement) */ 
/** @attribute StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.TreeViewItem) */ 
public class TreeViewItem extends HeaderedItemsControl
TemplatePartAttribute(Name="PART_Header", Type=System.Windows.FrameworkElement) 
StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.TreeViewItem) 
public class TreeViewItem extends HeaderedItemsControl
<TreeViewItem>
  Items
</TreeViewItem>

Content Model: The TreeViewItem control is a HeaderedItemsControl and has three content properties: Header, Items, and ItemsSource. For information about how to set these properties, see the Headered Items Control Content Model overview.

TreeViewItem controls can be embedded inside other TreeViewItem controls to create a hierarchy of nodes inside a TreeView control.

The following illustration shows a hierarchy of TreeViewItem controls inside a TreeView.

TreeView illustration

To expand or collapse a TreeViewItem, use the IsExpanded property.

For more information about the TreeView control, see the TreeView Overview.

The following example shows how to create a hierarchy of TreeViewItem controls in a TreeView control.

<TreeView Name="myTreeViewEvent" >
  <TreeViewItem Header="Employee1" IsSelected="True">
    <TreeViewItem Header="Jesper Aaberg"/>
    <TreeViewItem Header="Employee Number">
      <TreeViewItem Header="12345"/>
    </TreeViewItem>
    <TreeViewItem Header="Work Days">
      <TreeViewItem Header="Monday"/>
      <TreeViewItem Header="Tuesday"/>
      <TreeViewItem Header="Thursday"/>
    </TreeViewItem>
  </TreeViewItem>
  <TreeViewItem Header="Employee2">
    <TreeViewItem Header="Dominik Paiha"/>
    <TreeViewItem Header="Employee Number">
      <TreeViewItem Header="98765"/>
    </TreeViewItem>
    <TreeViewItem Header="Work Days">
      <TreeViewItem Header="Tuesday"/>
      <TreeViewItem Header="Wednesday"/>
      <TreeViewItem Header="Friday"/>
    </TreeViewItem>
  </TreeViewItem>
</TreeView>

More Code

How to: Create Simple or Complex TreeViews

This example shows how to create simple or complex TreeView controls.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.ItemsControl
                 System.Windows.Controls.HeaderedItemsControl
                  System.Windows.Controls.TreeViewItem

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft