Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimate selected item of wpf listbox
    primarykey
    data
    text
    <p>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?</p> <pre><code>&lt;Style TargetType="{x:Type ListView}"&gt; &lt;Style.Setters&gt; &lt;Setter Property="BorderThickness" Value="5" /&gt; &lt;Setter Property="FontSize" Value="16" /&gt; &lt;Setter Property="FontFamily" Value="Arial" /&gt; &lt;Setter Property="ItemTemplate"&gt; &lt;Setter.Value&gt; &lt;DataTemplate x:Name="ListViewItemTemplate"&gt; &lt;TextBlock Text="{Binding}" Padding="0,0,5,5"/&gt; &lt;/DataTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;ControlTemplate.Triggers&gt; &lt;EventTrigger RoutedEvent="ListViewItemBase.Selected"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard TargetProperty="Color"&gt; &lt;ColorAnimation To="#FFFF0000" Duration="0:0:1" AutoReverse="true" /&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style.Setters&gt; &lt;/Style&gt; </code></pre> <hr> <p><strong>Working Version:</strong></p> <pre><code>&lt;Style TargetType="{x:Type ListView}"&gt; &lt;Style.Setters&gt; &lt;Setter Property="BorderThickness" Value="5" /&gt; &lt;Setter Property="FontSize" Value="16" /&gt; &lt;Setter Property="FontFamily" Value="Arial" /&gt; &lt;Setter Property="ItemTemplate"&gt; &lt;Setter.Value&gt; &lt;DataTemplate x:Name="ListViewItemTemplate"&gt; &lt;TextBlock Text="{Binding}" Padding="0,0,5,5"/&gt; &lt;/DataTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="ItemContainerStyle"&gt; &lt;Setter.Value&gt; &lt;Style&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="ListViewItem.IsSelected" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard Target="ListViewItem" TargetProperty="Background.Color"&gt; &lt;ColorAnimation To="Red" Duration="0:0:0.5" AutoReverse="true" /&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/Trigger.EnterActions&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style.Setters&gt; </code></pre> <p> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload