Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 2.26 KB

colorkeyframeanimation.md

File metadata and controls

50 lines (32 loc) · 2.26 KB
-api-id -api-type
T:Microsoft.UI.Composition.ColorKeyFrameAnimation
winrt class

Microsoft.UI.Composition.ColorKeyFrameAnimation

-description

A time-based animation that targets the Color property with one or more color key frames.

The ColorKeyFrameAnimation class is one of the supported types of KeyFrameAnimations that is used to animate the Color property off of the Brush property on a SpriteVisual. When working with ColorKeyFrameAnimation s, utilize Windows.UI.Color objects for the values of keyframes. Utilize the InterpolationColorSpace property to define which color space the system will interpolate through for the animation.

-remarks

Use the CompositionObject.StartAnimation and CompositionObject.StopAnimation methods to start and stop the animation.

An animation is associated with an object's property by calling CompositionObject.StartAnimation and specifying the property name and the animation. See the remarks section of CompositionObject.StartAnimation for a list of animatable properties.

-examples

void ColorAnimation(SpriteVisual visual)
{
  // Create the ColorKeyFrameAnimation
  var colorAnimation = _compositor.CreateColorKeyFrameAnimation();

  // Create the KeyFrames using Windows.UI.Color objects
  colorAnimation.InsertKeyFrame(0.5f, Colors.Purple);
  colorAnimation.InsertKeyFrame(1.0f, Colors.Cyan);

  // Set the interpolation to go through the HSL space
  colorAnimation.InterpolationColorSpace = CompositionColorSpace.Hsl;
  colorAnimation.Duration = TimeSpan.FromSeconds(3);
 
  // Apply the cubic-bezier to a KeyFrame
  visual.Brush.StartAnimation("Color", colorAnimation);
}
          

-see-also

Composition Animations Overview, KeyFrameAnimation, IClosable