development-plugin-for-avalonia

Animations, Composition, and Motion Architecture in Avalonia

Table of Contents

  1. Scope and Primary APIs
  2. Motion Rules
  3. Transition and Page-Transition Recipes
  4. Composition Animation Recipe
  5. Choosing Transitions vs Keyframes vs Composition
  6. AOT and Runtime Notes
  7. Do and Don’t Guidance
  8. Troubleshooting
  9. Official Resources

Scope and Primary APIs

Use this reference to move from basic hover polish to motion architecture that feels intentional.

Primary APIs:

Motion Rules

Motion should communicate one of four things:

  1. Relationship
    • how one surface relates to another during navigation or reveal.
  2. Confirmation
    • that an interaction was accepted.
  3. Emphasis
    • which surface is currently active or elevated.
  4. Continuity
    • how content changed without feeling disconnected.

Practical timing guidance:

Reduce motion when:

Transition and Page-Transition Recipes

Use transitions for simple state changes and page transitions for view swaps.

<Border xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Classes="interactive-card"
        Opacity="0.96"
        RenderTransform="translateY(0px)">
  <Border.Transitions>
    <Transitions>
      <TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.16" />
      <DoubleTransition Property="Opacity" Duration="0:0:0.16" />
    </Transitions>
  </Border.Transitions>
</Border>
<CompositePageTransition xmlns="https://github.com/avaloniaui"
                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                         x:Key="ShellPageTransition">
  <CompositePageTransition.PageTransitions>
    <PageSlide Duration="0:0:0.2" Orientation="Horizontal" />
    <CrossFade Duration="0:0:0.2" />
  </CompositePageTransition.PageTransitions>
</CompositePageTransition>

<TransitioningContentControl PageTransition="{StaticResource ShellPageTransition}"
                             Content="{CompiledBinding CurrentPage}" />

Composition Animation Recipe

Use composition when you need smoother, higher-frequency, or shell-level motion with less UI-thread churn.

using System;
using System.Numerics;
using Avalonia.Rendering.Composition;

var visual = ElementComposition.GetElementVisual(CardHost)!;
var compositor = visual.Compositor;

var slide = compositor.CreateVector3KeyFrameAnimation();
slide.InsertKeyFrame(0f, new Vector3(0, 8, 0));
slide.InsertKeyFrame(1f, new Vector3(0, 0, 0));
slide.Duration = TimeSpan.FromMilliseconds(180);

var fade = compositor.CreateScalarKeyFrameAnimation();
fade.InsertKeyFrame(0f, 0.88f);
fade.InsertKeyFrame(1f, 1f);
fade.Duration = TimeSpan.FromMilliseconds(180);

visual.StartAnimation("Offset", slide);
visual.StartAnimation("Opacity", fade);

var center = compositor.CreateExpressionAnimation(
    "Vector3(this.Target.Size.X * 0.5, this.Target.Size.Y * 0.5, 1)");
visual.StartAnimation("CenterPoint", center);

Use composition for:

Choosing Transitions vs Keyframes vs Composition

Use transitions when:

Use keyframe Animation when:

Use composition when:

AOT and Runtime Notes

Do and Don’t Guidance

Do:

Do not:

Troubleshooting

  1. Motion feels expensive.
    • Reduce animated properties, shorten duration, and move shell effects to composition.
  2. Page transitions feel disconnected.
    • Pair slide and fade only when both communicate continuity; otherwise use a simpler transition.
  3. Composition animation fails silently.
    • Check the target property string and ensure the visual belongs to the current compositor.

Official Resources