Animator

A running animation that can be paused, scrubbed by a gesture, reversed, or interrupted mid-flight.

Hold it in a field for as long as it runs: it owns a native peer, and a collected animator stops ticking.

public sealed class Animator : IDisposable

Properties

Fraction

How far the animation has run, from 0 to 1.

Assign it to scrub, e.g. from a drag.

Type: double

public double Fraction { get; set; }

IsReversed

Whether the animation is headed backwards, towards where it started.

Takes effect on the next Continue.

Type: bool

public bool IsReversed { get; set; }

IsRunning

Whether the animation is currently running on its own.

Type: bool

public bool IsRunning { get; }

Methods

Continue

Runs the animation from wherever it is towards its current heading.

For a spring, velocity carries the gesture's speed in, as full travels per second, positive towards the end.

public void Continue(
  double velocity = 0)
ParameterSummary
(optional) double velocityThe initial velocity in full travels per second.

Create

Prepares an animation of the changes made in changes.

It does not run until Start.

Only what changes touches is animated. Transforms, Opacity, CornerRadius, colors, gradients and layout lengths all interpolate; what has no in-between (a Material, a system color, an auto-sized Width) snaps when the animation settles.

public static Animator Create(
  Animation animation,
  Action changes)
ParameterSummary
Animation animationThe timing and easing to use.
Action changesThe property changes to capture.

Returns

Dispose

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

OnCompleted

Calls handler when the animation ends, with true if it reached the end rather than being interrupted.

public void OnCompleted(
  Action<bool> handler)
ParameterSummary
Action<bool> handlerThe completion callback.

Pause

Freezes the animation where it is, so Fraction can drive it instead.

public void Pause()

Reverse

Turns the animation around, keeping its momentum.

public void Reverse()

Start

Runs the animation, after delay seconds if given.

public void Start(
  double delay = 0)
ParameterSummary
(optional) double delayThe delay before starting, in seconds.

Stop

Ends the animation.

It settles where it is, unless finish jumps it to the end.

public void Stop(
  bool finish = false)
ParameterSummary
(optional) bool finishWhether to jump to the end before stopping.