Compartir a través de


HierarchicalDataTemplate Class

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

Represents a DataTemplate that supports HeaderedItemsControl objects, such as TreeViewItem.

Inheritance Hierarchy

System.Object
  System.Windows.DependencyObject
    System.Windows.FrameworkTemplate
      System.Windows.DataTemplate
        System.Windows.HierarchicalDataTemplate

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

Syntax

'Declaration
Public Class HierarchicalDataTemplate _
    Inherits DataTemplate
public class HierarchicalDataTemplate : DataTemplate
<sdk:HierarchicalDataTemplate .../>

The HierarchicalDataTemplate type exposes the following members.

Constructors

  Name Description
Public method HierarchicalDataTemplate Initializes a new instance of the HierarchicalDataTemplate class.

Top

Properties

  Name Description
Public property DataType Gets or sets the type for which this DataTemplate is intended. (Inherited from DataTemplate.)
Public property Dispatcher Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Public property ItemContainerStyle Gets or sets the Style that is applied to the item container for each child item.
Public property ItemsSource Gets or sets the binding that is used to generate content for the next sublevel in the data hierarchy.
Public property ItemTemplate Gets or sets the DataTemplate to apply to the ItemTemplate property on a generated HeaderedItemsControl, such as a TreeViewItem, to indicate how to display items in the next sublevel in the data hierarchy.

Top

Methods

  Name Description
Public method CheckAccess Determines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public method ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetAnimationBaseValue Returns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Public method LoadContent Creates the UIElement objects in the DataTemplate. (Inherited from DataTemplate.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Public method SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

The HierarchicalDataTemplate enables you to set a data template for the current level of hierarchical data, as well as, set the template for the next sublevel with the ItemTemplate property. Use a HierarchicalDataTemplate to display hierarchical data in a control, such as a TreeView.

Examples

The following example shows two hierarchical data templates declared as resources.

<StackPanel.Resources>
    <sdk:HierarchicalDataTemplate x:Key="ChildTemplate" >
       <TextBlock FontStyle="Italic" Text="{Binding Path=Title}" />
     </sdk:HierarchicalDataTemplate>
    <sdk:HierarchicalDataTemplate x:Key="NameTemplate" 
        ItemsSource="{Binding Path=ChildTopics}" 
        ItemTemplate="{StaticResource ChildTemplate}">
        <TextBlock Text="{Binding Path=Title}" FontWeight="Bold" />
        </sdk:HierarchicalDataTemplate>
</StackPanel.Resources>

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.

Thread Safety

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