Sorry for the cryptic post title, but this one is handy if you're using Storyboards in WPF to animate properties.

I have an image that I'm scaling and rotating when the mouse pointer's moved over it. It looks great - the image kind of zooms in as you hover over it.

The rotation goes from 5 degrees to -3 degrees, and the scale goes from 1 to 2 times. When the IsMouseOver property returns to "false", the scale returns to 1 and the rotation to 5 degrees.

The problem I found, though, was that if the animation hadn't finished by the time you moved the mouse pointer off the image, there was a noticeable flicker as the image quickly scaled up to 2 times and rotated to -3 degrees.

The solution? Don't specify a "From" value for your animations. If you only specify a "To" value, then the property animates from whatever its current value is.

Here's the code for the trigger in my application as an example:

 <DataTrigger.EnterActions>
<
BeginStoryboard >
<
Storyboard>
<
ParallelTimeline>
<
DoubleAnimation
To="-3"
Duration="0:0:0.3"
Storyboard.TargetName="thumbnailRotation"
Storyboard.TargetProperty="Angle"/>
<
DoubleAnimation
To="2"
Duration="0:0:0.3"
Storyboard.TargetName="thumbnailScale"
Storyboard.TargetProperty="ScaleX"/>
<
DoubleAnimation
To="2"
Duration="0:0:0.3"
Storyboard.TargetName="thumbnailScale"
Storyboard.TargetProperty="ScaleY"/>
</
ParallelTimeline>
</
Storyboard>
</
BeginStoryboard>
</
DataTrigger.EnterActions>
<
DataTrigger.ExitActions>
<
BeginStoryboard>
<
Storyboard>
<
ParallelTimeline>
<
DoubleAnimation
To="5"
Duration="0:0:0.5"
Storyboard.TargetName="thumbnailRotation"
Storyboard.TargetProperty="Angle"/>
<
DoubleAnimation
To="1"
Duration="0:0:0.5"
Storyboard.TargetName="thumbnailScale"
Storyboard.TargetProperty="ScaleX"/>
<
DoubleAnimation
To="1"
Duration="0:0:0.5"
Storyboard.TargetName="thumbnailScale"
Storyboard.TargetProperty="ScaleY"/>
</
ParallelTimeline>
</
Storyboard>
</
BeginStoryboard>
</
DataTrigger.ExitActions>

As you see, I only specify DoubleAnimation.To ... so the image nicely pops back to where it was when the mouse leaves it.