Module 3 · Lesson 13 of 16
Transitions for state, animations for attention
A transition animates the property change that already happened. A keyframe animation runs on a clock. Neither belongs in a view model.
Motion in a desktop app has one job: explain what changed. It is not decoration, and it is not a place to put logic.
Two different tools
Transitions watch a property and interpolate from the old value to the new one.
You set the final value; Avalonia does the travel.
<Border Classes="slider" Classes.on="{Binding IsOn}" />
<Style Selector="Border.slider">
<Setter Property="RenderTransform" Value="translateX(0px)" />
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Property="RenderTransform"
Duration="0:0:0.35" Easing="CubicEaseOut" />
</Transitions>
</Setter>
</Style>
Animation runs on a timeline whether or not anything changed — a pulsing dot, a
progress shimmer, a one-shot entrance.
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="0.4" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</UserControl.Styles>
<ScrollViewer>
<StackPanel Classes="page" Spacing="28">
<shell:PageHeader
Kicker="Lesson 15 · Motion"
Title="Transitions for state, animations for attention"
Blurb="A transition animates the property change that already happened. A keyframe animation runs on a clock. Neither belongs in a view model, and both must be skippable." />
Notice that neither block is in the view model. The view model exposes IsOn; the
view decides that "on" means 220 pixels to the right, over 350 ms.
Animate the cheap properties
RenderTransform and Opacity are composed on the GPU and do not invalidate layout.
Width, Height, Margin, and Padding re-run measure and arrange on every frame.
If a panel must grow, animate a transform and keep the layout static.
Reduced motion is not optional. If your product has a reduce-motion setting, set
Transitionsto an empty collection in that style. The state still changes; only the travel disappears. Do not silently ignore the preference.
Durations that do not feel broken
- 100–150 ms: hover, press, small colour changes.
- 200–350 ms: panels sliding, pages fading.
- Over 500 ms: only for something the user is waiting on.
Easing matters more than duration. CubicEaseOut for things entering, CubicEaseIn
for things leaving, linear only for progress.
Try it
- Change the travel to
translateX(320px)and the duration to 600 ms. It will feel slow — that is the point of the exercise. - Add a
DoubleTransitiononOpacityand fade the panel as it slides. - Add a reduce-motion style that removes the transition, and verify the class still toggles with the animation gone.
Files this lesson draws from
src/CourseApp/Lessons/15_Motion/MotionView.axamlsrc/CourseApp/Lessons/15_Motion/MotionViewModel.cs
VerifiedThe verifier toggles the view model and asserts the slider's `on` class follows it, then captures the page. The motion itself is visual.