I have a ListBox, and there are a few items. How can I change the Background of the ListBoxItem, when mouse hovers it? I tried with this code, but it returns error:
<Window.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Opacity" Value="0.6" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Trigger.Setters>
<Setter Property="Opacity" Value="1.0" />
</Trigger.Setters>
</Trigger>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Background" To="Orange" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Background" To="White" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
Use a ColorAnimation
instead of DoubleAnimation
:
<ColorAnimation Duration="0:0:0.3"
Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="Orange" />