Compartilhar via


LinearColorKeyFrame

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Animates from the Color value of the previous key frame to the Value of the current key frame, by using linear interpolation.

<LinearColorKeyFrame   .../>

Managed Equivalent

LinearColorKeyFrame

Remarks

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

Linear key frames, such as LinearColorKeyFrame, create a smooth linear interpolation between values.

For more information on basic concepts, see Key-Frame Animations. Note that the Key-Frame Animations topic is written primarily for users of the managed API, and may not have code examples or specific information that address the JavaScript API scenarios.

Example

The following example uses the ColorAnimationUsingKeyFrames class to animate the Background property of a Canvas object. 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, such as 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, such as 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, such as SplineColorKeyFrame, create a variable transition between values according to the values of the KeySpline property. In this example, the change in color begins slowly and speeds up exponentially toward the end of the time segment.

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  Width="200" Height="200"
  Background="White"
  x:Name="Page">
  <Canvas.Triggers>
    <EventTrigger RoutedEvent="Canvas.Loaded">
      <BeginStoryboard>
        <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" />

          </ColorAnimationUsingKeyFrames>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Canvas.Triggers>
</Canvas>

See Also

Reference