Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've been able to reproduce your erroneous results using the following code (I'm stumped too):</p> <pre><code>&lt;ListBox&gt; &lt;ListBox.ItemContainerStyle&gt; &lt;Style TargetType="ListBoxItem"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ListBoxItem}"&gt; &lt;ControlTemplate.Resources&gt; &lt;Storyboard x:Key="BorderAnimationToRed"&gt; &lt;ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="Red" Duration="0:0:0.1" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="BorderAnimationToBlue"&gt; &lt;ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="Blue" Duration="0:0:0.1" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="BorderAnimationToOrange"&gt; &lt;ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="Orange" Duration="0:0:0.1" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="BorderAnimationToWhite"&gt; &lt;ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="White" Duration="0:0:0.1" /&gt; &lt;/Storyboard&gt; &lt;/ControlTemplate.Resources&gt; &lt;Border Name="Border" BorderBrush="DarkGray" BorderThickness="1" Margin="3"&gt; &lt;ContentPresenter /&gt; &lt;Border.Background&gt; &lt;SolidColorBrush /&gt; &lt;/Border.Background&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard Storyboard="{StaticResource BorderAnimationToOrange}"/&gt; &lt;/Trigger.EnterActions&gt; &lt;Trigger.ExitActions&gt; &lt;BeginStoryboard Storyboard="{StaticResource BorderAnimationToWhite}"/&gt; &lt;/Trigger.ExitActions&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard Storyboard="{StaticResource BorderAnimationToBlue}"/&gt; &lt;/Trigger.EnterActions&gt; &lt;Trigger.ExitActions&gt; &lt;BeginStoryboard Storyboard="{StaticResource BorderAnimationToWhite}"/&gt; &lt;/Trigger.ExitActions&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/ListBox.ItemContainerStyle&gt; &lt;ListBox.Items&gt; &lt;sys:String&gt;hey&lt;/sys:String&gt; &lt;sys:String&gt;du&lt;/sys:String&gt; &lt;sys:String&gt;dux&lt;/sys:String&gt; &lt;sys:String&gt;duy&lt;/sys:String&gt; &lt;sys:String&gt;dua&lt;/sys:String&gt; &lt;/ListBox.Items&gt; </code></pre> <p></p> <p>This code is a little easier to read, as the visuals, resources, and triggers are declared separately. Maybe you could try to use EventTriggers to accomplish your goal (using the "ListBoxItem.MouseEnter" and "ListBoxItem.MouseLeave" routed events). Good luck!</p>
 

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