How can I change the background color of TreeViewItem when it is hovered over?
After reading a few articles/questions, including this one WPF TreeView Highlight Row On Hover, I thought the appropriate action to take was to create a style template for my TreeView as such:
<Style x:Key="TreeViewItemStyle1" TargetType="{x:Type TreeViewItem}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>
Then assign it to my TreeView:
<TreeView ItemsSource="{Binding Folders}"
ItemContainerStyle="{DynamicResource TreeViewItemStyle1}"/>
But that doesn't appear to work. It does change the color as I hover over it but it leaves highlighted making my TreeView look totally messed up:
I've tried resetting the color when IsMouseOver is false:
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="White" />
</Trigger>
But it still leaves multiple nodes highlighted and only resets them when I move over them one at the time.
Any ideas?
Thanks.