如何使用C#/ WPF动画上的MouseEnter和鼠标离开事件列表框的项目? [英] How to animate ListBox Items on MouseEnter and MouseLeave events using C#/WPF?
问题描述
我无法捕捉/触发OnMouseEnter在或通过C#code列表项OnMouseLeave在事件。需要明确的是,我并不需要一个OnSelectedItem事件。
I can't capture/trigger OnMouseEnter or OnMouseLeave events through C# code for list items. To be clear, I don't need an OnSelectedItem event.
我想要做的是能够处理ListBoxItem的的OnMouseEnter在和OnMouseLeave在事件,将启动DoubleAnimation是为ListBoxItem的 - 我想扩大在它的MouseEnter字体和还原到鼠标离开原来的大小。
What I want to do is to be able to handle the OnMouseEnter and OnMouseLeave events for ListBoxItem which will start the DoubleAnimation for that ListBoxItem - I want to enlarge its font on MouseEnter and restore to original size on MouseLeave.
任何想法?谢谢你。
推荐答案
像这样的东西(如ListBox的DataTemplate中的一部分):
Something like this (as part of the ListBox's 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/
这篇关于如何使用C#/ WPF动画上的MouseEnter和鼠标离开事件列表框的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!