Get the height of a TreeViewItem's Header in WPF
I am trying to find the height of the header section of a TreeViewItem in order to draw an adorner. I have an instance of the TreeViewItem however, I am not sure how to get the VisualTreeRootNode for the header element in code. I am looking for something like:
FrameworkElement headerElement =
_myTreeViewItem.HeaderT开发者_如何学JAVAemplate.GetVisualTreeRootNode();
How can I achieve this?
private FrameworkElement GetHeaderControl(TreeViewItem item)
{
return (FrameworkElement)item.Template.FindName("PART_Header", item);
}
Many of the default templates are listed in examples on MSDN. For instance:
http://msdn.microsoft.com/en-us/library/ms788727.aspx
You can also see the name of the template part in the definition of the control here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem(v=VS.100).aspx
As one of the Attributes attached to the class. This is a generalized mechanism for drilling down into templates on any well-defined WPF Control.
精彩评论