Take the 2-minute tour ×

I am using a WPF treeview with couple of heierachical datatemplates. Treeview has a drag drop capability.

Can someone please help me to get the selected TreeViewItem's Header section height (Actual Height). If I get the selected items ActualHeight(TreeViewItem.ActualHeight) then it will give the height with the children. But I want is only the Header elements height. I achived this by using a VisualTree search to find a control (border) inside the data template which covers the entire header. What I want is a more faster way of doing this (Faster than the visual tree search) since I am doing this inside a DragOver event of the treeview.

share|improve this question
+1 for mentioning that ActualHeight is the height with the children. –  Helge Klein Nov 27 '10 at 21:32
add comment

1 Answer

up vote 2 down vote accepted

TreeViewItem has a named part for the header called PART_Header, and you can use ControlTemplate.FindName to get a reference to that part. Note that it could be missing if the control template has been changed and the new template does not actually render the header.

var header = treeViewItem.Template.FindName("PART_Header", treeViewItem)
    as FrameworkElement;
if (header != null)
    var height = header.ActualHeight;

(The Border you are currently using is probably the parent of this element, so you may get slightly different results).

share|improve this answer
add comment

Your Answer


