Search code examples
wpfheadertreeviewitem

Change TreeViewItem Header by trigger


Having such Style

<Style TargetType="TreeViewItem">
  <Style.Triggers>
    <Trigger Property="IsExpanded" Value="True">
      <Setter Property="Header" Value="Pink"></Setter>
    </Trigger>
  </Style.Triggers>
</Style>

I would expect the text of the expanded TreeViewItems to be "Pink", but nothing set actually. If I change to Property="Background" instead, it works. How Header differs from Background?


Solution

  • I think I'll need more info to answer this more completely. However, if I have to guess, I'd say you're probably setting the Header property on the TreeViewItem explicitly like this:

    <TreeView>
        <TreeViewItem
            Header="Blue"/>
    </TreeView>
    

    And, in this case, setting it explicitly will override anything that you put in the style.