如何使用C#/ WPF为MouseEnter和MouseLeave事件上的ListBox项目设置动画?
作者:互联网
我无法通过C#代码捕获/触发列表项目的OnMouseEnter或OnMouseLeave事件.需要明确的是,我不需要OnSelectedItem事件.
我想要做的是能够处理ListBoxItem的OnMouseEnter和OnMouseLeave事件,该事件将启动该ListBoxItem的DoubleAnimation-我想在MouseEnter上放大其字体,并在MouseLeave上恢复其原始大小.
有任何想法吗?谢谢.
解决方法:
这样的事情(作为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/
标签:listboxitem,animation,wpf,c 来源: https://codeday.me/bug/20191107/2003765.html