views:

426

answers:

2

Could anyone explain how HierarchicalDataTemplate works

  • What Controls supports HierarchicalDataTemplate?
  • What does a control need to support HierarchicalDataTemplate?

UPDATE

  • What causes the TreeView to render the parent and child nodes when the same HierarchicalDataTemplate in a HeaderedItemsControl only causes the parent to be rendered?
+3  A: 

What Controls supports HierarchicalDataTemplate?

All controls that inherit HeaderedItemsControl, such as TreeViewItem or MenuItem

What does a control need to support HierarchicalDataTemplate?

Inheriting from HeaderedItemsControl should be enough

Thomas Levesque
A: 

Such control needs to be of type HeaderedItemsControl or derived from it. The current framework controls that do are MenuItem, ToolBar and TreeViewItem.

The HeaderedItemsControl overrides the PrepareContainerForItemOverride method and somewhere along that call path checks for HierarchicalDataTemplate.

kek444
So what causes the TreeView to render the parent and child nodes when the same HierarchicalDataTemplate in a HeaderedItemsControl only causes the parent to be rendered?
thmsn
The DataTemplate doesn't "cause" the parent to be rendered. HierarchicalDataTemplate has an ItemsSource property which is automatically applied to the HeaderedItemsControl's ItemsSource in code. Otherwise it's like a usual ItemScontrol.
kek444