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?
-
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.
-
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):
- Property system coercion
- Active animations, or animations with a Hold behavior
- Local value
- TemplatedParent template
- Style triggers
- Template triggers
- Style setters
- Theme style
- Inheritance
- 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.
0 comments:
Post a Comment