This documentation is archived and is not being maintained.

PointAnimationUsingPath Class

Animates the value of a Point property between two or more target values using a PathGeometry to specify those values. This animation can be used to move a visual object along a path.

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

public class PointAnimationUsingPath : PointAnimationBase
<PointAnimationUsingPath .../>

PointAnimationUsingPath uses linear interpolation over a specified Duration.

PointAnimationUsingPath is particularly well suited for animating the position of an object on the screen if the object uses a Point property to specify position.

This example shows how to use a PointAnimationUsingPath object to animate a Point along a curved path.

The following example moves an EllipseGeometry along a path defined by a PathGeometry. The ellipse geometry's Center property, which takes a Point value, specifies its position; to move the ellipse geometry, you animate its Center property. The example uses a PointAnimationUsingPath to animate the EllipseGeometry object's Center property.

  <Canvas Width="400" Height="400">

    <Path Fill="Blue" Margin="15,15,15,15">

        <!-- The EllipseGemetry specifies the shape and position of the Ellipse. The
        Center property is animated, causing the Ellipse to animate across the screen-->
        <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
          Center="10,100" RadiusX="15" RadiusY="15" />
        <EventTrigger RoutedEvent="Path.Loaded">
          <BeginStoryboard Name="MyBeginStoryboard">

              <!-- Animates the ellipse along the path. -->
                RepeatBehavior="Forever" >
                    Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"
                    PresentationOptions:Freeze="True" />
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SDKSample

    public class PointAnimationUsingPathExample : Page

        public PointAnimationUsingPathExample()

            // Create a NameScope for the page so that 
            // we can use Storyboards.
            NameScope.SetNameScope(this, new NameScope());

            // Create the EllipseGeometry to animate.
            EllipseGeometry animatedEllipseGeometry =
                new EllipseGeometry(new Point(10, 100), 15, 15);

            // Register the EllipseGeometry's name with 
            // the page so that it can be targeted by a 
            // storyboard. 
            this.RegisterName("AnimatedEllipseGeometry", animatedEllipseGeometry);

            // Create a Path element to display the geometry.
            Path ellipsePath = new Path();
            ellipsePath.Data = animatedEllipseGeometry;
            ellipsePath.Fill = Brushes.Blue;
            ellipsePath.Margin = new Thickness(15);

            // Create a Canvas to contain ellipsePath 
            // and add it to the page.
            Canvas mainPanel = new Canvas();
            mainPanel.Width = 400;
            mainPanel.Height = 400;
            this.Content = mainPanel;

            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure pFigure = new PathFigure();
            pFigure.StartPoint = new Point(10, 100);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();
            pBezierSegment.Points.Add(new Point(35, 0));
            pBezierSegment.Points.Add(new Point(135, 0));
            pBezierSegment.Points.Add(new Point(160, 100));
            pBezierSegment.Points.Add(new Point(180, 190));
            pBezierSegment.Points.Add(new Point(285, 200));
            pBezierSegment.Points.Add(new Point(310, 100));

            // Freeze the PathGeometry for performance benefits.

            // Create a PointAnimationgUsingPath to move 
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation = 
                new PointAnimationUsingPath();
            centerPointAnimation.PathGeometry = animationPath;
            centerPointAnimation.Duration = TimeSpan.FromSeconds(5);
            centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the Center property 
            // of the EllipseGeometry named "AnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, "AnimatedEllipseGeometry");
                new PropertyPath(EllipseGeometry.CenterProperty));

            // Create a Storyboard to contain and apply the animation.
            Storyboard pathAnimationStoryboard = new Storyboard();
            pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            pathAnimationStoryboard.AutoReverse = true;

            // Start the Storyboard when ellipsePath is loaded.
            ellipsePath.Loaded += delegate(object sender, RoutedEventArgs e)
                // Start the storyboard.



For the complete sample, see Path Animation Sample.

The code version of the preceding sample used a Storyboard to animate the EllipseGeometry, even though only one animation was applied. A Storyboard is often the easiest way to apply multiple animations because these animations can be controlled by the same Storyboard. However, an easier way to apply a single animation to a property when using code is to use the BeginAnimation method. For an example, see How to: Animate a Property Without Using a Storyboard.

More Code

How to: Rotate an Object by Using a Geometric Path This example shows how to rotate (pivot) an object along a geometric path that is defined by a PathGeometry object.
How to: Animate an Object Along a Path (Double Animation) This example shows how to use the DoubleAnimationUsingPath class to move an object along a path defined by a PathGeometry.
How to: Animate an Object Along a Path (Matrix Animation) This example shows how to use the MatrixAnimationUsingPath class to animate an object along a path that is defined by a PathGeometry.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0