动画WPF列表框的选定项目 [英] Animate selected item of wpf listbox
本文介绍了动画WPF列表框的选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
结果
我试图建立一个全球性的风格在我的应用程序的所有列表框。下面是我使用了XAML code。在这里,我试图触发出来的动画,但它不工作。我只想对所选项目的动画。任何帮助吗?
I'm trying to set a global style for all the listboxes in my application. Below is the xaml code that i've used. Here i've tried to trigger out an animation but it doesn't work. I just want an animation on the selected item. Any help?
<Style TargetType="{x:Type ListView}">
<Style.Setters>
<Setter Property="BorderThickness" Value="5" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate x:Name="ListViewItemTemplate">
<TextBlock Text="{Binding}" Padding="0,0,5,5"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ListViewItemBase.Selected">
<BeginStoryboard>
<Storyboard TargetProperty="Color">
<ColorAnimation To="#FFFF0000" Duration="0:0:1" AutoReverse="true" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
工作版本:
<Style TargetType="{x:Type ListView}">
<Style.Setters>
<Setter Property="BorderThickness" Value="5" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate x:Name="ListViewItemTemplate">
<TextBlock Text="{Binding}" Padding="0,0,5,5"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style>
<Style.Triggers>
<Trigger Property="ListViewItem.IsSelected" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard Target="ListViewItem" TargetProperty="Background.Color">
<ColorAnimation To="Red" Duration="0:0:0.5" AutoReverse="true" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
</Style.Setters>
推荐答案
为ListBox创建ItemContainerStyle和和添加触发器为ListBoxItem.IsSelected ==真
Create ItemContainerStyle for the ListBox and and Add Trigger for ListBoxItem.IsSelected == True
这篇关于动画WPF列表框的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文