0

Как правильно установить <EventTrigger RoutedEvent="PreviewMouseMove">, чтобы ListBoxItem менял цвет?

<ListBox Grid.Column="0" ItemsSource="{Binding Category}" Background="#171717">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <ListBoxItem>
                            <ListBoxItem.Content>
                                <StackPanel Orientation="Horizontal">
                                    <Image></Image>
                                    <TextBlock Text="{Binding Name}"></TextBlock>
                                </StackPanel>
                            </ListBoxItem.Content>
                        </ListBoxItem>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Background" Value="LightSteelBlue"/>
                        <Setter Property="Padding" Value="5"/>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Foreground" Value="White"/>
                                <Setter Property="BorderThickness" Value="0"/>
                                <Setter Property="Background" Value="Red"></Setter>
                            </Trigger>
                            <EventTrigger RoutedEvent="PreviewMouseMove">
                                <!--<Setter Property="Foreground" Value="Black"/> как реализовать такие сеттеры?
                                <Setter Property="BorderThickness" Value="2"/>
                                <Setter Property="Background" Value="Red"/>-->
                            </EventTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

1 ответ 1

1
<EventTrigger RoutedEvent="PreviewMouseMove">
    <BeginStoryboard>
        <Storyboard>
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(ListBoxItem.Background).(SolidColorBrush.Color)">
                <EasingColorKeyFrame KeyTime="0" Value="Red" />
            </ColorAnimationUsingKeyFrames>
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(ListBoxItem.BorderThickness)">
                <EasingThicknessKeyFrame KeyTime="0" Value="2"/>
            </ThicknessAnimationUsingKeyFrames>
        </Storyboard>
    </BeginStoryboard>
</EventTrigger>

При изменении таким же образом Foreground - ошибки, так что будьте осторожны)

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.