Avalonia graphics animation

From linuxdevel/Avalonia-skills · View interactive version

Avalonia graphics animation is an AI agent skill from the GitHub repository linuxdevel/Avalonia-skills. Use when working with Avalonia brushes, transforms, geometry, clipping, animations, transitions, or bitmap effects. Covers SolidColorBrush, LinearGradientBrush, RadialGradientBrush, ConicGradientBrush, ImageBrush, VisualBrush, RenderTransform, shapes, Path geometry, clipping, BoxShadow, keyframe Ani

How to use this skill

Skill file

Avalonia Graphics & Animation

Overview

Avalonia renders via Skia (the only built-in renderer in 12; Direct2D1 was removed). All visual effects are cross-platform. Animations use keyframe Animation class or property Transitions.

Brushes

| Brush | XAML | Use |

|---|---|---|

| SolidColorBrush | "#FF5722" or "Red" | Solid fill/stroke |

| LinearGradientBrush | <LinearGradientBrush> | Linear gradient |

| RadialGradientBrush | <RadialGradientBrush> | Radial gradient |

| ConicGradientBrush | <ConicGradientBrush> | Conic gradient |

| ImageBrush | <ImageBrush> | Tiled/stretched image fill |

| VisualBrush | <VisualBrush> | Render control as brush |

<Rectangle Width="200" Height="100">
    <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0%,0%" EndPoint="100%,100%">
            <GradientStop Color="#FF5722" Offset="0"/>
            <GradientStop Color="#9C27B0" Offset="1"/>
        </LinearGradientBrush>
    </Rectangle.Fill>
</Rectangle>
<Rectangle Width="200" Height="200">
    <Rectangle.Fill>
        <RadialGradientBrush GradientOrigin="50%,50%" RadiusX="50%" RadiusY="50%">
            <GradientStop Color="Yellow" Offset="0"/>
            <GradientStop Color="Red" Offset="1"/>
        </RadialGradientBrush>
    </Rectangle.Fill>
</Rectangle>

RadialGradientBrush.Radius was removed in 12 — use RadiusX/RadiusY (12.0+). (11.x: Radius="50%".)

Opacity shorthand: Opacity="0.5" on any control (applies to whole subtree).

Transforms

<Rectangle RenderTransform="rotate(45)" Width="100" Height="100"/>
<Rectangle>
    <Rectangle.RenderTransform>
        <TransformGroup>
            <RotateTransform Angle="45"/>
            <ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
            <TranslateTransform X="20" Y="10"/>
            <SkewTransform AngleX="10"/>
        </TransformGroup>
    </Rectangle.RenderTransform>
</Rectangle>

RenderTransformOrigin="0.5,0.5" — pivot point (0–1 relative to control bounds).

String shorthand syntax: rotate(deg), scale(x,y), translate(x,y), skew(x,y), matrix(a,b,c,d,e,f).

Geometry / Shapes

Shapes (draw themselves): Rectangle, Ellipse, Line, Polyline, Polygon, Path

<Path Fill="CornflowerBlue" Stroke="Navy" StrokeThickness="2"
      Data="M 50,0 L 100,100 L 0,100 Z"/>
<Ellipse Fill="Red" Width="80" Height="60"/>
<Line StartPoint="0,0" EndPoint="100,100" Stroke="Black" StrokeThickness="2"/>

Geometry (reusable shape data): EllipseGeometry, RectangleGeometry, PathGeometry, CombinedGeometry, GeometryGroup

<Path>
    <Path.Data>
        <CombinedGeometry GeometryCombineMode="Xor">
            <CombinedGeometry.Geometry1>
                <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50"/>
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <EllipseGeometry Center="80,50" RadiusX="50" RadiusY="50"/>
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
    </Path.Data>
</Path>

Clipping

<Border ClipToBounds="True" CornerRadius="8">
    <Image Source="..." Stretch="UniformToFill"/>
</Border>

Custom clip geometry:

<Rectangle Width="100" Height="100" Fill="Red">
    <Rectangle.Clip>
        <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50"/>
    </Rectangle.Clip>
</Rectangle>

Shadows

BoxShadow only on Border:

<Border BoxShadow="0 4 8 0 #40000000" CornerRadius="8" Background="White">
    <TextBlock Text="Shadowed"/>
</Border>

Multiple shadows:

<Border BoxShadow="0 2 4 0 #20000000, 0 8 16 0 #10000000" CornerRadius="8"/>

Format: offsetX offsetY blur spread color [inset]

Animations (Keyframe)

<Window.Styles>
    <Style Selector="Button.spin">
        <Style.Animations>
            <Animation Duration="0:0:1" IterationCount="INFINITE" PlaybackDirection="Normal">
                <KeyFrame Cue="0%">
                    <Setter Property="RenderTransform" Value="rotate(0)"/>
                </KeyFrame>
                <KeyFrame Cue="100%">
                    <Setter Property="RenderTransform" Value="rotate(360)"/>
                </KeyFrame>
            </Animation>
        </Style.Animations>
    </Style>
</Window.Styles>

Animation with easing and delay:

<Animation Duration="0:0:0.5" Delay="0:0:0.1" FillMode="Forward" Easing="CubicEaseOut">
    <KeyFrame Cue="0%">
        <Setter Property="Opacity" Value="0"/>
        <Setter Property="RenderTransform" Value="translateY(-20px)"/>
    </KeyFrame>
    <KeyFrame Cue="100%">
        <Setter Property="Opacity" Value="1"/>
        <Setter Property="RenderTransform" Value="translateY(0)"/>
    </KeyFrame>
</Animation>

| Property | Values |

|---|---|

| Duration | h:m:s format |

| Delay | h:m:s format |

| IterationCount | number or INFINITE |

| PlaybackDirection | Normal / Reverse / Alternate / AlternateReverse |

| FillMode | None / Forward / Backward / Both |

| Easing | LinearEasing, CubicEaseIn/Out/InOut, BounceEaseOut, SplineEasing, etc. |

| PlaybackBehavior (12.0+) | Auto / Always / OnlyIfVisible — see below |

Trigger animation from code:

var animation = new Animation
{
    Duration = TimeSpan.FromSeconds(0.3),
    FillMode = FillMode.Forward,
    Children =
    {
        new KeyFrame { Cue = Cue.Parse("0%"), Setters = { new Setter(OpacityProperty, 0.0) } },
        new KeyFrame { Cue = Cue.Parse("100%"), Setters = { new Setter(OpacityProperty, 1.0) } }
    }
};
await animation.RunAsync(myControl);

(12.0+) Style animations no longer tick while the control is hidden (IsVisible=false / not in the visual tree). To keep them running set PlaybackBehavior="Always" on the Animation:

<Animation Duration="0:0:1" IterationCount="INFINITE" PlaybackBehavior="Always"> ... </Animation>

Easing/animator renames (12.0+): CubicBezierEasing → SplineEasing (custom cubic-bezier curve); CustomAnimatorBase/CustomAnimatorBase<T> → InterpolatingAnimator<T> for custom animators. (11.x: the old names, obsolete in late 11.x, removed in 12.)

Transitions (Property Change)

Smooth property changes on value set:

<Border Background="Blue">
    <Border.Transitions>
        <Transitions>
            <BrushTransition Property="Background" Duration="0:0:0.3"/>
            <DoubleTransition Property="Opacity" Duration="0:0:0.2" Easing="CubicEaseOut"/>
            <TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.3"/>
        </Transitions>
    </Border.Transitions>
</Border>

| Transition Type | Property Types |

|---|---|

| BrushTransition | IBrush |

| ColorTransition | Color |

| DoubleTransition | double |

| FloatTransition | float |

| IntegerTransition | int |

| PointTransition | Point |

| SizeTransition | Size |

| ThicknessTransition | Thickness |

| TransformOperationsTransition | ITransform / string transform |

| VectorTransition | Vector |

In styles (apply to all matching controls):

<Style Selector="Button">
    <Setter Property="Transitions">
        <Transitions>
            <DoubleTransition Property="Opacity" Duration="0:0:0.15"/>
        </Transitions>
    </Setter>
</Style>

Text Rendering & Letter Spacing (12.0+)

<TextBlock Text="Spaced" TextElement.LetterSpacing="2" />   <!-- inherited attached property; TextBlock LetterSpacing="2" still works in XAML -->
<Panel TextOptions.TextRenderingMode="Antialias" />

| 11.x | 12.0+ |

|---|---|

| RenderOptions.TextRenderingMode | TextOptions.TextRenderingMode (TextOptions also has TextHintingMode, BaselinePixelAlignment) |

| TextBlock.LetterSpacingProperty (C#) | TextElement.LetterSpacingProperty |

Custom Drawing & Composition (12.0+ changes)

Rendering Performance (12.1+)

Page Transitions (Carousel/Navigation)

<Carousel.PageTransition>
    <PageSlide Duration="0:0:0.35" Orientation="Horizontal"/>
</Carousel.PageTransition>
<Carousel.PageTransition>
    <CrossFade Duration="0:0:0.25"/>
</Carousel.PageTransition>

Composite:

<Carousel.PageTransition>
    <CompositePageTransition>
        <PageSlide Duration="0:0:0.3" Orientation="Horizontal"/>
        <CrossFade Duration="0:0:0.3"/>
    </CompositePageTransition>
</Carousel.PageTransition>

Community Graphics Libraries

| Library | NuGet | Purpose |

|---|---|---|

| Svg.Skia | Svg.Skia | SVG rendering in Avalonia via Skia |

| LiveCharts2 | LiveChartsCore.SkiaSharpView.Avalonia | Animated, interactive charts and gauges |

| ScottPlot | ScottPlot.Avalonia | Fast data plotting |

| OxyPlot | OxyPlot.Avalonia | Scientific plotting |

| PanAndZoom | PanAndZoom | Pan/zoom container with Skia backend |

| Aura3D | GitHub: CeSun/Aura3D | Lightweight 3D rendering control |

| GoDiagram | Northwoods.GoAvalonia | Interactive diagram/graph control |

| AvaloniaGraphControl | AvaloniaGraphControl | Auto-layout graph panel (Microsoft MSAGL) |

| Core2D | GitHub: wieslawsoltes/Core2D | 2D diagram editor library |

SVG in Avalonia

<!-- NuGet: Svg.Skia -->
<Image>
    <Image.Source>
        <svg:SvgImage Source="avares://MyApp/Assets/icon.svg"/>
    </Image.Source>
</Image>

Or use SvgImage control directly from Svg.Skia.Avalonia package.

Common Mistakes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.