Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MatrixTransform Class

Creates an arbitrary affine matrix transformation that is used to manipulate objects or coordinate systems in a 2-D plane.

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

public sealed class MatrixTransform : Transform
public final class MatrixTransform extends Transform
public final class MatrixTransform extends Transform
<MatrixTransform .../>
<object property="m11, m12, m31, m22, offsetX, offsetY"/>
- or -
<object property="Identity"/>
 m11   System.Double  The value at position (1, 1) of the transformation Matrix.   m12   System.Double  The value at position (1, 2) of the transformation Matrix.  m21   System.Double  The value at position (2, 1) of the transformation Matrix.  m22   System.Double  The value at position (2, 2) of the transformation Matrix.  offsetX   System.Double  The value at position (3, 1) of the transformation Matrix.  offsetY   System.Double  The value at position (3, 2) of the transformation Matrix. 

Use the MatrixTransform class to create custom transformations that are not provided by the RotateTransform, SkewTransform, ScaleTransform, or TranslateTransform classes.

A 3x3 matrix is used for transformations in a 2-D x-y plane. You can multiply affine matrix transformations to form linear transformations, such as rotation and skew (shear) that are followed by translation.

An affine matrix transformation has its final column equal to (0, 0, 1); therefore, you only have to specify the members in the first two columns.

A Windows Presentation Foundation (WPF) Matrix has the following structure:

The members in the last row, OffsetX and OffsetY, represent translation values.

Methods and properties usually specify the transformation matrix as a vector that has only six members; the members are as follows:

    (M11, M12, M21, M22, OffsetX, OffsetY)

This example shows how to use a MatrixTransform to translate (move) the position, stretch, and skew of a Button.

NoteNote:

Use the MatrixTransform class to create custom transformations that are not provided by the RotateTransform, SkewTransform, ScaleTransform, or TranslateTransform classes.

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

      <Button MinWidth="100">Click
        <Button.RenderTransform>
          <MatrixTransform x:Name="myMatrixTransform">
            <MatrixTransform.Matrix >
              
              <!-- OffsetX and OffsetY specify the position of the button,
              M11 stretches it, and M12 skews it. -->
              <Matrix OffsetX="10" OffsetY="100" M11="3" M12="2"/>
            </MatrixTransform.Matrix>
          </MatrixTransform>
        </Button.RenderTransform>
      </Button>
    </Canvas>
  </StackPanel>
</Page>

More Code

How to: Animate a Matrix by Using Key Frames

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

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.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.GeneralTransform
             System.Windows.Media.Transform
              System.Windows.Media.MatrixTransform
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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.