This documentation is archived and is not being maintained.

SplineVector3DKeyFrame.KeySpline Property

Gets or sets the two control points that define animation progress for this key frame.

Namespace:  System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)

public KeySpline KeySpline { get; set; }
    <KeySpline .../>
<object KeySpline="KeySpline" .../>

Property Value

Type: System.Windows.Media.Animation.KeySpline
The two control points that specify the cubic Bezier curve which defines the progress of the key frame.

Identifier field


Metadata properties set to true


To understand how a KeySpline works, it is helpful to understand cubic Bezier curves. A cubic Bezier curve is defined by a start point, an end point, and two control points. The two coordinates in the KeySpline defines those two control points. When describing key splines, the start point of the Bezier curve is always 0, and the end point is always 1, which is why you define only the two control points. The resulting curve specifies how an animation is interpolated during a time segment; that is, the curve represents the rate of change in the animation's target attribute over the time segment. To better see the relationship between animation progress and a Bezier curve, see Key Spline Animation Sample .

This example shows how to animate the value of a property that takes a Double by using key frames.

The following example moves a rectangle across a screen. The example uses the DoubleAnimationUsingKeyFrames class to animate the X property of a TranslateTransform applied to a Rectangle. This animation, which repeats indefinitely, uses three key frames in the following manner:

  1. During the first three seconds, uses an instance of the LinearDoubleKeyFrame class to move the rectangle along a path at a steady rate from its starting position to the 500 position. Linear key frames like LinearDoubleKeyFrame create a smooth linear transition between values.

  2. At the end of the fourth second, uses an instance of the DiscreteDoubleKeyFrame class to suddenly move the rectangle to the next position. Discrete key frames like DiscreteDoubleKeyFrame create sudden jumps between values. In this example, the rectangle is at the starting position and then suddenly appears at the 500 position.

  3. In the final two seconds, uses an instance of the SplineDoubleKeyFrame class to move the rectangle back to its starting position. Spline key frames like SplineDoubleKeyFrame create a variable transition between values according to the value of the KeySpline property. In this example, the rectangle begins by moving slowly and then speeds up exponentially toward the end of the time segment.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media;

namespace Microsoft.Samples.KeyFrameExamples
    /// <summary>
    /// This example shows how to use the DoubleAnimationUsingKeyFrames class to
    /// animate the position of an object.
    /// Key frame animations enable you to create complex animations 
    /// by specifying multiple destination values
    /// and controlling the animation's interpolation method.
    /// </summary>
    public class AltDoubleAnimationUsingKeyFramesExample : Page
        public AltDoubleAnimationUsingKeyFramesExample()
            Title = "DoubleAnimationUsingKeyFrames Example";
            Background = Brushes.White;
            Margin = new Thickness(20);

            // Create a NameScope for this page so that
            // Storyboards can be used.
            NameScope.SetNameScope(this, new NameScope());

            // Create a rectangle.
            Rectangle aRectangle = new Rectangle();
            aRectangle.Width = 100;
            aRectangle.Height = 100;
            aRectangle.Stroke = Brushes.Black;
            aRectangle.StrokeThickness = 5;

            // Create a Canvas to contain and
            // position the rectangle.
            Canvas containerCanvas = new Canvas();
            containerCanvas.Width = 610;
            containerCanvas.Height = 300;
            Canvas.SetTop(aRectangle, 100);
            Canvas.SetLeft(aRectangle, 10);         

            // Create a TranslateTransform to 
            // move the rectangle.
            TranslateTransform animatedTranslateTransform = 
                new TranslateTransform();
            aRectangle.RenderTransform = animatedTranslateTransform;  

            // Assign the TranslateTransform a name so that
            // it can be targeted by a Storyboard.
                "AnimatedTranslateTransform", animatedTranslateTransform);

            // Create a DoubleAnimationUsingKeyFrames to
            // animate the TranslateTransform.
            DoubleAnimationUsingKeyFrames translationAnimation 
                = new DoubleAnimationUsingKeyFrames();
            translationAnimation.Duration = TimeSpan.FromSeconds(6);

            // Animate from the starting position to 500
            // over the first second using linear
            // interpolation.
                new LinearDoubleKeyFrame(
                    500, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))) // KeyTime

            // Animate from 500 (the value of the previous key frame) 
            // to 400 at 4 seconds using discrete interpolation.
            // Because the interpolation is discrete, the rectangle will appear
            // to "jump" from 500 to 400.
                new DiscreteDoubleKeyFrame(
                    400, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4))) // KeyTime

            // Animate from 400 (the value of the previous key frame) to 0
            // over two seconds, starting at 4 seconds (the key time of the
            // last key frame) and ending at 6 seconds.
                new SplineDoubleKeyFrame(
                    0, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6)), // KeyTime
                    new KeySpline(0.6,0.0,0.9,0.0) // KeySpline

            // Set the animation to repeat forever. 
            translationAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the X property
            // of the object named "AnimatedTranslateTransform."
            Storyboard.SetTargetName(translationAnimation, "AnimatedTranslateTransform");
                translationAnimation, new PropertyPath(TranslateTransform.XProperty));

            // Create a storyboard to apply the animation.
            Storyboard translationStoryboard = new Storyboard();

            // Start the storyboard after the rectangle loads.
            aRectangle.Loaded += delegate(object sender, RoutedEventArgs e)

            Content = containerCanvas;


<!-- This example shows how to use the DoubleAnimationUsingKeyFrames to 
     animate the position of an object. 
     Key frame animations enable you to create complex animations 
     by specifying multiple destination values
     and controlling the animation's interpolation method.
  Title="DoubleAnimationUsingKeyFrames Example"
  Background="White" Margin="20">       
  <Canvas Width="610" Height="300">

    <!-- The position of this rectangle is animated using 
         a key frame animation. -->
        <TranslateTransform x:Name="AnimatedTranslateTransform" />

        <EventTrigger RoutedEvent="Rectangle.Loaded">

              <!-- Animate the TranslateTransform.X property using 3 KeyFrames
                   which animates the rectangle along a straight line. 
                   This animation repeats indefinitely. -->

                <!-- Using a LinearDoubleKeyFrame, the rectangle moves 
                     steadily from its starting position to 500 over 
                     the first 3 seconds.  -->
                <LinearDoubleKeyFrame Value="500" KeyTime="0:0:3" />

                <!-- Using a DiscreteDoubleKeyFrame, the rectangle suddenly 
                     appears at 400 after the fourth second of the animation. -->
                <DiscreteDoubleKeyFrame Value="400" KeyTime="0:0:4" />

                <!-- Using a SplineDoubleKeyFrame, the rectangle moves 
                     back to its starting point. The
                     animation starts out slowly at first and then speeds up. 
                     This KeyFrame ends after the 6th
                     second. -->
                <SplineDoubleKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0" KeyTime="0:0:6" />

For the complete sample, see KeyFrame Animation Sample.

For consistency with other animation examples, the code versions of this example use a Storyboard object to apply the DoubleAnimationUsingKeyFrames. Alternatively, when applying a single animation in code, it is simpler to use the BeginAnimation method instead of using a Storyboard. For an example, see How to: Animate a Property Without Using a Storyboard.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.