This documentation is archived and is not being maintained.

How to: Animate a Rectangle

This example shows how to animate changes to the size and position of a rectangle.


The following example uses an instance of the RectAnimation class to animate the Rect property of a RectangleGeometry, which animates changes to the size and position of the rectangle.

<Page  xmlns=""
  xmlns:x="" >
  <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
    <Path Stroke="Black" StrokeThickness="1" Fill="LemonChiffon">
        <RectangleGeometry x:Name="myRectangleGeometry" Rect="0,200,100,100" />
        <EventTrigger RoutedEvent="Path.Loaded">
              <!-- Animate the Rect property of the RectangleGeometry which causes the
              rectangle to animate postion and size. -->
              Storyboard.TargetProperty ="Rect"
              Duration="0:0:2" FillBehavior="HoldEnd" From="0,200,100,100" To="600,50,200,50" />

See Also