1

我有一个 ListBox,并且有一些项目。当鼠标悬停时,如何更改 ListBoxItem 的背景?我尝试使用此代码,但它返回错误:

<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>
4

1 回答 1

2

使用 aColorAnimation代替DoubleAnimation

<ColorAnimation Duration="0:0:0.3" 
                Storyboard.TargetProperty="Background.(SolidColorBrush.Color)" 
                To="Orange" />
于 2013-07-20T18:47:25.717 回答