我无法通过列表项的 C# 代码捕获/触发 OnMouseEnter 或 OnMouseLeave 事件。需要明确的是,我不需要 OnSelectedItem 事件。
我想要做的是能够处理 ListBoxItem 的 OnMouseEnter 和 OnMouseLeave 事件,这将为该 ListBoxItem 启动 DoubleAnimation - 我想在 MouseEnter 上放大其字体并在 MouseLeave 上恢复到原始大小。
有任何想法吗?谢谢。
像这样的东西(作为列表框数据模板的一部分):
<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>
via http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)