ColorAnimationUsingKeyFrames class

Applies to Windows and Windows Phone

Animates the value of a Color property along a set of key frames.




public sealed class ColorAnimationUsingKeyFrames : Timeline

<ColorAnimationUsingKeyFrames ...>

XAML Values


One or more object elements that define the key frames for the animation. These object elements represent one of the classes deriving from ColorKeyFrame. These are typically any combination of LinearColorKeyFrame, DiscreteColorKeyFrame, EasingColorKeyFrame, and SplineColorKeyFrame. Object elements defined here become members of the collection when code accesses the ColorAnimationUsingKeyFrames.KeyFrames property at run time.




The ColorAnimationUsingKeyFrames class has these types of members:


The ColorAnimationUsingKeyFrames class has these constructors.

ColorAnimationUsingKeyFrames Initializes a new instance of the ColorAnimationUsingKeyFrames class.



The ColorAnimationUsingKeyFrames class has these events.

Completed Occurs when the Storyboard object has completed playing. (Inherited from Timeline)



The ColorAnimationUsingKeyFrames class has these methods. It also inherits methods from the Object class.

ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)



The ColorAnimationUsingKeyFrames class has these properties.

PropertyAccess typeDescription


Read/writeGets or sets a value that indicates whether the timeline plays in reverse after it completes a forward iteration. (Inherited from Timeline)


Read/writeGets or sets the time at which this Timeline should begin. (Inherited from Timeline)


Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)


Read/writeGets or sets the length of time for which this timeline plays, not counting repetitions. (Inherited from Timeline)


Read/writeGets or sets a value that declares whether animated properties that are considered dependent animations should be permitted to use this animation declaration.


Read-onlyIdentifies the EnableDependentAnimation dependency property.


Read/writeGets or sets a value that specifies how the animation behaves after it reaches the end of its active period. (Inherited from Timeline)


Read-onlyGets the collection of ColorKeyFrame objects that define the animation.


Read/writeGets or sets the repeating behavior of this timeline. (Inherited from Timeline)


Read/writeGets or sets the rate, relative to its parent, at which time progresses for this Timeline. (Inherited from Timeline)



The following example uses the ColorAnimationUsingKeyFrames class to animate the Background property of a StackPanel. This animation uses three key frames in the following manner:

  1. During the first two seconds, LinearColorKeyFrame gradually changes the color from green to red. Linear key frames like LinearColorKeyFrame create a smooth linear transition between values.

  2. During the end of the next half second, DiscreteColorKeyFrame quickly changes the color from red to yellow. Discrete key frames like DiscreteColorKeyFrame create sudden changes between values; the animation occurs quickly and has no interpolation at all between values.

  3. During the final two seconds, SplineColorKeyFrame changes the color again, this time from yellow back to green. Spline key frames like SplineColorKeyFrame create a variable transition between values according to the values of the KeySpline property. A KeySpline provides a way to alter the relationship of time versus value during the animation duration to be nonlinear, and in particular the relationship can be a curve that would be difficult to produce with individual key frames. In this example, the change in color begins slowly and speeds up exponentially toward the end of the time segment.

<StackPanel x:Name="myStackPanel" Background="Red"
        <Storyboard x:Name="colorStoryboard">

            <ColorAnimationUsingKeyFrames Storyboard.TargetName="myStackPanel" 
                <!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
                a smooth, linear animation between values. -->
                <LinearColorKeyFrame Value="Blue" KeyTime="00:00:02" />

                <!-- In the next half second, go to yellow. DiscreteColorKeyFrame creates a 
                sudden jump between values. -->
                <DiscreteColorKeyFrame Value="Yellow" KeyTime="00:00:2.5" />

                <!-- In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame 
                creates a variable transition between values depending on the KeySpline property. In this example,
                the animation starts off slow but toward the end of the time segment, it speeds up exponentially.-->
                <SplineColorKeyFrame Value="Green" KeyTime="00:00:4.5" KeySpline="0.6,0.0 0.9,0.00" />


// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)


Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Media::Animation [C++]



See also

Storyboarded animations



© 2014 Microsoft