I am trying to set a global style for all lists in my application. Below is the xaml code I used. Here I tried to call the animation, but it does not work. I just want the 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>
Working version:
<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>
source
share