首先,在listboxitem模板样式中添加<eventtrigger/>,如下:
<EventTrigger RoutedEvent="ListBoxItem.Loaded"> <BeginStoryboard> <Storyboard x:Name="ColorStoryboard" BeginTime="00:00:00"> <ColorAnimation x:Name="colorAni" BeginTime="00:00:00" Storyboard.TargetProperty="(ListBoxItem.Foreground).(SolidColorBrush.Color)" From="Red" To="Green" Duration="0:0:0.3" RepeatBehavior="Forever" AutoReverse="True"/> </Storyboard> </BeginStoryboard> </EventTrigger>
随后在C#代码中对listboxitem.style赋值
listboxitem.Style=(Style)this.FindResource("ListBoxItemAnimationStyle")
执行后发现EventTrigger并没有被触发,而其他如background等值均已修改,讨教各位是什么原因?该怎么样修改?
或简单点说,怎么样在后台动态添加listboxitem并且对其添加动画,谢谢!
解决方案:20分