Good question ... of course, this can be done by overriding the template, but it's pain ... (if you want to go this way, extract the template using StyleSnooper or ShowMeTheTemplate and change VerticalAlignmentto ToggleButton)
- TreeViewItem OnApply. ToggleButton ( "Expander" ) , VerticalAlignment, :
public class TopAlignedTreeViewItem : TreeViewItem
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (Template != null)
{
ToggleButton btn = Template.FindName("Expander", this) as ToggleButton;
if (btn != null)
{
btn.VerticalAlignment = VerticalAlignment.Top;
}
}
}
}
TreeView TopAlignedTreeViewItem TreeViewItem s, TreeView:
public class TopAlignedTreeView : TreeView
{
protected override bool IsItemItsOwnContainerOverride(object item)
{
return (item is TopAlignedTreeViewItem);
}
protected override System.Windows.DependencyObject GetContainerForItemOverride()
{
return new TopAlignedTreeViewItem();
}
}