3

我无法通过 C# 代码为列表项捕获/触发 OnMouseEnter 或 OnMouseLeave 事件。需要明确的是,我不需要 OnSelectedItem 事件。

我想要做的是能够处理 ListBoxItem 的 OnMouseEnter 和 OnMouseLeave 事件,这将启动该 ListBoxItem 的 DoubleAnimation - 我想在 MouseEnter 上放大其字体并在 MouseLeave 上恢复到原始大小。

有任何想法吗?谢谢。

4

1 回答 1

4

像这样的东西(作为 ListBox 的 DataTemplate 的一部分):

<DataTemplate.Triggers>
    <EventTrigger
        SourceName="BorderControl"
        RoutedEvent="TextBlock.MouseEnter">
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BorderControl"
                    Storyboard.TargetProperty="Background.Color"
                    To="DarkRed" Duration="00:00:00.2" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
    <EventTrigger
        SourceName="BorderControl"
        RoutedEvent="TextBlock.MouseLeave">
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BorderControl"
                    Storyboard.TargetProperty="Background.Color"
                    To="WhiteSmoke" Duration="00:00:00.2" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</DataTemplate.Triggers>

通过http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/

于 2009-06-02T22:14:32.370 回答