【问题标题】:How to animate ListBox Items on MouseEnter and MouseLeave events using C#/WPF?如何使用 C#/WPF 在 MouseEnter 和 MouseLeave 事件上为 ListBox 项设置动画?
【发布时间】:2009-06-02 22:09:47
【问题描述】:

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

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

有什么想法吗?谢谢。

【问题讨论】:

    标签: c# wpf animation listboxitem


    【解决方案1】:

    类似这样的东西(作为 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多