Export (0) Print
Expand All

MatrixAnimationUsingKeyFrames Class

Animates the value of a Matrix property along a set of KeyFrames.

Namespace: System.Windows.Media.Animation
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[ContentPropertyAttribute("KeyFrames")] 
public class MatrixAnimationUsingKeyFrames : MatrixAnimationBase, IKeyFrameAnimation, IAddChild
/** @attribute ContentPropertyAttribute("KeyFrames") */ 
public class MatrixAnimationUsingKeyFrames extends MatrixAnimationBase implements IKeyFrameAnimation, IAddChild
ContentPropertyAttribute("KeyFrames") 
public class MatrixAnimationUsingKeyFrames extends MatrixAnimationBase implements IKeyFrameAnimation, IAddChild
<MatrixAnimationUsingKeyFrames>
  KeyFrames
</MatrixAnimationUsingKeyFrames>

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

This example shows how to animate the Matrix property of a MatrixTransform by using key frames.

The following example uses the MatrixAnimationUsingKeyFrames class to animate the Matrix property of a MatrixTransform. The example uses the MatrixTransform object to transform the appearance and position of a Button.

This animation uses the DiscreteMatrixKeyFrame class to create two key frames and does the following with them:

  1. Animates the first Matrix during the first 0.2 seconds. The example changes the M11 and M12 properties of the Matrix. This change causes the button to stretch and become skewed. The example also changes the OffsetX and OffsetY properties so that the button changes position.

  2. Animates the second Matrix at 1.0 seconds. The button moves to another position while the button is no longer skewed or stretched.

  3. Repeats the animation indefinitely.

NoteNote:

Key frames that derive from the DiscreteMatrixKeyFrame object create sudden jumps between values, that is, the movement of the animation is jerky.

<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  Title="MatrixAnimationUsingPath Example">
  <StackPanel Margin="20">
    <Canvas HorizontalAlignment="Left" Width="340" Height="240" >

      <!-- The Button that is animated. -->
      <Button Margin="-30,0,0,0" MinWidth="100">
        Click
        <Button.RenderTransform>
          <MatrixTransform x:Name="myMatrixTransform">
            <MatrixTransform.Matrix >
              <Matrix OffsetX="10" OffsetY="100"/>
            </MatrixTransform.Matrix>
          </MatrixTransform>
        </Button.RenderTransform>
        <Button.Triggers>
          <EventTrigger RoutedEvent="Button.Loaded">
            <BeginStoryboard>
              <Storyboard>

                <!-- Animates the button's MatrixTransform using MatrixAnimationUsingKeyFrames. 
                Animates to first Matrix in the first 0.2 seconds, to second Matrix in the next
                second, and then starts over. Notice that the first KeyFrame stretches the button
                and skews it using the M11 and M12 Matrix properties respectively. Also, animations are 
                using Discrete interpolation, so the MatrixTransform appears to "jump" from one value 
                to the next. -->
                <MatrixAnimationUsingKeyFrames
                Storyboard.TargetName="myMatrixTransform"
                Storyboard.TargetProperty="Matrix"
                Duration="0:0:3" 
                RepeatBehavior="Forever">
                  <DiscreteMatrixKeyFrame KeyTime="0:0:0.2">
                    <DiscreteMatrixKeyFrame.Value>
                      <Matrix OffsetX="100" OffsetY="200" M11="3" M12="1" />
                    </DiscreteMatrixKeyFrame.Value>
                  </DiscreteMatrixKeyFrame>
                  <DiscreteMatrixKeyFrame KeyTime="0:0:1">
                    <DiscreteMatrixKeyFrame.Value>
                      <Matrix OffsetX="300" OffsetY="100" M11="1" M12="0" />
                    </DiscreteMatrixKeyFrame.Value>
                  </DiscreteMatrixKeyFrame>
                </MatrixAnimationUsingKeyFrames>
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger>

        </Button.Triggers>
      </Button>

    </Canvas>
  </StackPanel>
</Page>

For the complete sample, see KeyFrame Animation Sample.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.Animation.Timeline
             System.Windows.Media.Animation.AnimationTimeline
               System.Windows.Media.Animation.MatrixAnimationBase
                System.Windows.Media.Animation.MatrixAnimationUsingKeyFrames

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft