I have a control template for TreeViewI开发者_JS百科tems
and instead of showing the normal FocusVisualStyle
I have a MultiTrigger
set up like this:
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="IsSelectionActive" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="FontWeight" Value="Bold"/>
</MultiTrigger>
However this also causes the FontWeight
to change to bold when a TreeViewItem's
parent item is selected. Is there any way I can stop that from happening?
Great question. It has to do with dependency property value precedence.
This is happening because the child tree view items do not override the FontWeight property in any way so they are inheriting it from their visual parent. What you could do is add another normal Trigger for when IsSelected is false.
<Trigger Property="IsSelected" Value="false">
<Setter Property="FontWeight" Value="Normal" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="IsSelectionActive" Value="true"/>
</MultiTrigger.Conditions>
<Setter Property="FontWeight" Value="Bold"/>
</MultiTrigger>
Now the child TreeViewItem will have its FontWeight property set by a trigger that will override the inherited property from its selected parent.
精彩评论