views:

479

answers:

2

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?

+3  A: 

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.

dustyburwell
+1  A: 

To elaborate on ascalonx's answer:

copied from Josh Smith's blog:

There is a well-defined set of rules which is used internally by WPF to figure out what the real value of a DP is. Here is a brief summary of the rules of precedence used when resolving the value of a DP (from highest to lowest priority):

  1. Property system coercion
  2. Active animations, or animations with a Hold behavior
  3. Local value
  4. TemplatedParent template
  5. Style triggers
  6. Template triggers
  7. Style setters
  8. Theme style
  9. Inheritance
  10. Default value from dependency property metadata

So if you explicitly set the Header property, (or if you bind it I think), you have that problem.

Denis Troller