Поделиться через


PointAnimationUsingKeyFrames

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

Animates the value of a Point along a set of KeyFrames.

<PointAnimationUsingKeyFrames>
  oneOrMorePointKeyFrames
</PointAnimationUsingKeyFrames>

XAML Values

Value

Description

oneOrMorePointKeyFrames

One or more PointKeyFrame object elements that define the key frames for the animation. These can be any combination of LinearPointKeyFrame, DiscretePointKeyFrame, and SplinePointKeyFrame object elements. Object elements defined here become members of the KeyFrames collection when scripting accesses the KeyFrames property at run time..

Managed Equivalent

PointAnimationUsingKeyFrames

Remarks

A key frame animation's target values are defined by its KeyFrames property, which contains a collection of PointKeyFrame objects. Each PointKeyFrame defines a segment of the animation with its own target Value and KeyTime properties. When the animation runs, it progresses from one key value to the next at the specified key times.

There are three types of PointKeyFrame classes, one for each supported interpolation method: LinearPointKeyFrame, DiscretePointKeyFrame, and SplinePointKeyFrame.

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 moves an ellipse along a triangular path. The example uses a PointAnimationUsingKeyFrames object to animate the Center property of an EllipseGeometry object. This animation uses three key frames in the following manner:

  1. During the first half second, a LinearPointKeyFrame object moves the ellipse along a path at a steady rate from its starting position. Linear key frames, such as LinearPointKeyFrame, create a smooth linear interpolation between values.

  2. During the end of the next half second, a DiscretePointKeyFrame object suddenly moves the ellipse along the path to the next position. Discrete key frames, such as DiscretePointKeyFrame, create sudden jumps between values.

  3. During the final two seconds, a SplinePointKeyFrame object moves the ellipse back to its starting position. Spline key frames, such as SplinePointKeyFrame, create a variable transition between values according to the values of the KeySpline property. In this example, the animation 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="400" Height="300">
  <Path Fill="Blue">
    <Path.Data>

      <!-- Describes an ellipse. -->
      <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
       Center="200,100" RadiusX="15" RadiusY="15" />
    </Path.Data>

    <Path.Triggers>
      <EventTrigger RoutedEvent="Path.Loaded">
        <BeginStoryboard>
          <Storyboard>

            <!-- Animating the Center property uses three KeyFrames, which animate
                 the ellipse along a triangular path. -->
            <PointAnimationUsingKeyFrames
              Storyboard.TargetProperty="Center"
              Storyboard.TargetName="MyAnimatedEllipseGeometry"
              Duration="0:0:5" RepeatBehavior="Forever">

              <!-- Over the first half second, using a LinearPointKeyFrame, the ellipse 
                   moves steadily from its starting position along the first line of the 
                   triangular path.  -->
              <LinearPointKeyFrame 
                KeyTime="0:0:0.5"
                Value="100,300" />

              <!-- Using a DiscretePointKeyFrame, the ellipse suddenly changes position
                   after the first second of the animation. -->
              <DiscretePointKeyFrame 
                KeyTime="0:0:1"
                Value="400,300" />

              <!-- Using a SplinePointKeyFrame, the ellipse moves back to its starting
                   position. It moves slowly at first and then speeds up. This key frame 
                   takes 2 seconds to complete. -->
              <SplinePointKeyFrame 
                KeySpline="0.6,0.0 0.9,0.00" 
                KeyTime="0:0:3"
                Value="200,100" />
            </PointAnimationUsingKeyFrames>
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Path.Triggers> 
  </Path>
</Canvas>