Animations

Animate layout and visual state with curves, springs, and gesture-driven animators.

View.Animate captures property changes made in its action and transitions the affected views to their new state:

View.Animate(
    Animation.Spring(duration: 0.5, damping: 0.72),
    () =>
    {
        card.Width = expanded ? 280 : 84;
        card.CornerRadius = expanded ? 22 : 16;
        details.Opacity = expanded ? 1 : 0;
        artwork.Scale = expanded ? 1 : 0.85;
    });

Layout lengths, transforms, opacity, corner radius, custom colors, and compatible gradients interpolate. Values without a meaningful intermediate representation (such as a material, system color, or an auto-sized width) settle to the final state without interpolation.

Timing

Animation.Default is 0.3 seconds with EaseInOut. Use Animation.Ease(duration, easing) for Linear, EaseIn, EaseOut, or EaseInOut. Use Animation.Spring(duration, damping) for physical settling; lower damping produces more bounce.

After(seconds) returns the same timing with a start delay:

Animation.Ease(0.25, Easing.EaseOut).After(0.1)

The overload with a completion callback receives true when the animation reached its end and false when it was interrupted.

Interactive animators

Use Animator when a gesture needs to pause, scrub, reverse, or continue an animation:

Animator animator = Animator.Create(
    Animation.Spring(0.5, damping: 0.75),
    () => card.Translation = new Point(180, 0));

animator.Fraction = 0;

card.Panned = gesture =>
{
    if (gesture.State is GestureState.Began)
        animator.Pause();
    else if (gesture.State is GestureState.Changed)
        animator.Fraction = Math.Clamp(gesture.Translation.X / 180, 0, 1);
    else
    {
        animator.IsReversed = animator.Fraction < 0.5;
        animator.Continue(gesture.Velocity.X / 180);
    }
};

Start, Pause, Continue, Reverse, and Stop control playback. Fraction is zero at the captured start and one at the end. OnCompleted registers completion handlers.

Keep an animator in a field for as long as it may run and dispose it when its owning object is finished. It owns a native display link; collecting or disposing it stops the animation from ticking.

Gesture callbacks that commonly drive interactive animators are covered in commands and gestures.