DiscreteColorKeyFrame Object

Animates from the Color value of the previous key frame to its own Value using discrete values.

<DiscreteColorKeyFrame .../>
To create an object using scripting, see CreateFromXAML.


KeyTime, Name, Value


Equals, FindName, GetHost, GetValue, SetValue


A key frame defines a segment of the ColorAnimationUsingKeyFrames to which it belongs. Each key frame has a target Value and a KeyTime. The KeyTime specifies the time at which the key frame's Value should be reached. A key frame animates from the target value of the previous key frame to its own target value. It starts when the previous key frame ends and ends when its own key time is reached.

Discrete key frames like DiscreteColorKeyFrame create sudden "jumps" between values (no interpolation). The animated property does not change until the key frame's key time is reached at which point the animated property goes suddenly to the target value.


The following example uses the ColorAnimationUsingKeyFrames class to animate the Background property of a Canvas. 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.
  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 keyframes. In this example, the change in color begins slowly and speeds up exponentially toward the end of the time segment.
  Width="200" Height="200"
    <EventTrigger RoutedEvent="Canvas.Loaded">
        <Storyboard x:Name="ColorStoryboard">
          <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Page" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
            <!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
            a smooth, linear animation between values. -->
            <LinearColorKeyFrame Value="Red" 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" />

See Also

Silverlight Key-Frame Animations Overview