Animations in WPF
WPF's animation system is built on the concept of a Timeline that describes how a value changes over a Duration, and an AnimationClock that drives the timeline on the WPF composition thread rather than the UI thread, which is why animations stay smooth even when application code is busy. Every animatable dependency property — such as Width, Opacity, or a Color inside a brush — has a matching animation type, for example DoubleAnimation for Width or Opacity, ColorAnimation for a Color, and ThicknessAnimation for a Margin, each specifying From, To, or By values plus a Duration.
Cricket analogy: Much like a Hawk-Eye ball-tracking system computing a smooth predicted trajectory independent of what the commentator is saying live, WPF's AnimationClock runs on the composition thread independent of what the UI thread is doing.
From/To/By Animations and Easing
A typical DoubleAnimation specifies From (the starting value, defaulting to the property's current value if omitted), To (the target value), and Duration; a By animation instead adds a delta to the starting value, which is useful for relative movement regardless of current position. EasingFunctions like QuadraticEase, BounceEase, or ElasticEase attach via EasingMode (EaseIn, EaseOut, EaseInOut) to replace the default linear interpolation with acceleration curves, and KeySpline-based animations (using SplineDoubleKeyFrame) give even finer control by specifying custom Bezier-based velocity curves between explicit KeyFrames at named times.
Cricket analogy: This is like a fast bowler's run-up that accelerates gradually to the crease rather than sprinting at constant speed the whole way, similar to an EaseIn easing function accelerating a DoubleAnimation instead of moving linearly.
<Button Content="Animate Me" Width="120" Height="40">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
From="120" To="240" Duration="0:0:0.4">
<DoubleAnimation.EasingFunction>
<BackEase EasingMode="EaseOut" Amplitude="0.4" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>Animating Non-Numeric and Discrete Properties
Not every property changes continuously — a discrete state like Visibility or an enum property does not have a meaningful in-between value, so WPF provides ObjectAnimationUsingKeyFrames with DiscreteObjectKeyFrame entries that snap the property to a new value at a specific KeyTime instead of interpolating. ColorAnimation and PointAnimation, by contrast, do interpolate continuously between color channels or coordinate pairs. A crucial performance detail is that many animations run on properties backed by RenderTransform (TranslateTransform, ScaleTransform, RotateTransform) rather than Margin or layout-affecting properties, because transform-based animation is handled by the composition/render thread without triggering an expensive WPF layout pass on every frame.
Cricket analogy: This is like a scoreboard that snaps directly from '3rd Wicket' to '4th Wicket' the instant a batsman is out, with no intermediate fractional wicket state, just like DiscreteObjectKeyFrame snaps a Visibility value at a KeyTime instead of interpolating.
Prefer animating RenderTransform properties (TranslateTransform.X/Y, ScaleTransform.ScaleX/Y, RotateTransform.Angle) over Margin, Width, or Canvas.Left when possible. Transform animations bypass WPF's layout pass entirely and are composited on the render thread, giving noticeably smoother results, especially for frequent or long-running animations like a loading spinner.
By default, most animations set the local value of the target property with a higher precedence than a plain property setter, and after the animation completes the property may snap back to its pre-animation value unless FillBehavior is set to HoldEnd or the animation explicitly sets a final value. This surprises many developers who expect the animated end state to persist.
- WPF animations are Timelines driven by an AnimationClock on the composition thread, independent of UI thread load.
- Each animatable type has a matching animation class: DoubleAnimation, ColorAnimation, ThicknessAnimation, PointAnimation, and more.
- From/To/By values plus Duration define the animated range; By adds a relative delta instead of an absolute target.
- EasingFunctions (QuadraticEase, BounceEase, ElasticEase, BackEase) reshape linear interpolation into acceleration/deceleration curves.
- ObjectAnimationUsingKeyFrames with DiscreteObjectKeyFrame snaps non-interpolable properties like Visibility at exact KeyTimes.
- Animating RenderTransform properties is more performant than animating layout-affecting properties like Margin or Width.
- FillBehavior.HoldEnd is often needed to keep an animated value from reverting after the animation completes.
Practice what you learned
1. What component actually drives a WPF Timeline's value changes over time?
2. Which animation type is used to animate a discrete, non-interpolable property like Visibility?
3. Why is animating a RenderTransform property generally more performant than animating Margin?
4. What does a By animation do differently from a To animation?
5. Why might an animated property revert to its original value after the animation finishes?
Was this page helpful?
You May Also Like
Storyboards
Learn how WPF Storyboards group and orchestrate multiple Timelines, target elements and properties, and trigger animations from XAML or code.
Shapes and Brushes
Learn how WPF's Shape classes (Rectangle, Ellipse, Path, Polygon) draw vector graphics and how Brush types paint their interiors and outlines.
Custom Controls and User Controls
Compare WPF's two approaches to building reusable controls — lightweight, composition-based UserControl versus fully templatable, lookless custom Control.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesMVVM Design Pattern Study Notes
.NET · 30 topics