title | description | ms.date | helpviewer_keywords | ms.assetid | |||
---|---|---|---|---|---|---|---|
How to: Animate a Matrix by Using Key Frames |
Learn how to use the MatrixAnimationUsingKeyFrames class to animate the Matrix property of a MatrixTransform by using key frames. |
03/30/2017 |
|
b851a4c7-ecb1-420e-9203-83e7afd037fd |
This example shows how to animate the xref:System.Windows.Media.MatrixTransform.Matrix%2A property of a xref:System.Windows.Media.MatrixTransform by using key frames.
The following example uses the xref:System.Windows.Media.Animation.MatrixAnimationUsingKeyFrames class to animate the xref:System.Windows.Media.MatrixTransform.Matrix%2A property of a xref:System.Windows.Media.MatrixTransform. The example uses the xref:System.Windows.Media.MatrixTransform object to transform the appearance and position of a xref:System.Windows.Controls.Button.
This animation uses the xref:System.Windows.Media.Animation.DiscreteMatrixKeyFrame class to create two key frames and does the following with them:
-
Animates the first xref:System.Windows.Media.Matrix during the first 0.2 seconds. The example changes the xref:System.Windows.Media.Matrix.M11%2A and xref:System.Windows.Media.Matrix.M12%2A properties of the xref:System.Windows.Media.Matrix. This change causes the button to stretch and become skewed. The example also changes the xref:System.Windows.Media.Matrix.OffsetX%2A and xref:System.Windows.Media.Matrix.OffsetY%2A properties so that the button changes position.
-
Animates the second xref:System.Windows.Media.Matrix at 1.0 seconds. The button moves to another position while the button is no longer skewed or stretched.
-
Repeats the animation indefinitely.
Note
Key frames that derive from the xref:System.Windows.Media.Animation.DiscreteMatrixKeyFrame object create sudden jumps between values, that is, the movement of the animation is jerky.
[!code-xamlkeyframes_snip#MatrixAnimationUsingKeyFramesWholePage]
For the complete sample, see KeyFrame Animation Sample.
- xref:System.Windows.Media.MatrixTransform.Matrix%2A
- xref:System.Windows.Media.MatrixTransform
- Key-Frame Animations Overview
- Key-Frame How-to Topics