This documentation is archived and is not being maintained.

# Matrix Structure

Visual Studio 2008

Represents a 3x3 affine transformation matrix used for transformations in 2-D space.

Namespace:  System.Windows.Media
Assembly:  WindowsBase (in WindowsBase.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

## Syntax

```[SerializableAttribute]
[TypeConverterAttribute(typeof(MatrixConverter))]
public value class Matrix : IFormattable
```
```<Matrix .../>
```
```<object property="m11, m12, m21, m22, offsetX, offsetY"/>
- or -
<object property="Identity"/>
```

#### XAML Values

m11

System::Double

The value in the first row and first column of this Matrix. For more information, see the M11 property.

m12

System::Double

The value in the first row and second column. For more information, see the M12 property.

m21

System::Double

The value in the second row and first column. For more information, see the M21 property.

m22

System::Double

The value in the second row and second column. For more information, see the M22 property.

offsetX

System::Double

The value in the third row and third column. For more information, see the OffsetX property.

offsetY

System::Double

The value in the third row and second column. For more information, see the OffsetY property.

## Remarks

A 3x3 matrix is used for transformations in a 2-D x-y plane. Affine transformation matrices can be multiplied to form any number of linear transformations, such as rotation and skew (shear), followed by translation. An affine transformation matrix has its final column equal to (0, 0, 1), so only the members in the first two columns need to be specified.  Note that vectors are expressed as row-vectors, not column vectors.

A WPF Matrix is stored using row-major order and has the following structure:

 M11 M12 0 M21 M22 0 OffsetX OffsetY 1

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

In methods and properties, the transformation matrix is usually specified as a vector with only six members, as follows:

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

Although you can use a Matrix structure directly to translate individual points, or with a MatrixTransform to transform objects, WPF also provides a set of classes that enable you to transform objects without working directly with matrices: RotateTransform, ScaleTransform, SkewTransform, and TranslateTransform.

## Examples

This example shows how to use a Matrix to transform Point and Vector objects.

```private void transformExamples()
{

Matrix myMatrix = new Matrix(5, 10, 15, 20, 25, 30);

//
// Transform a point.
//
Point myPoint = new Point(15,25);

// pointResult is (475, 680).
Point pointResult = myMatrix.Transform(myPoint);

//
// Transform an array of points.
//
Point[] myPointArray = new Point[]
{new Point(15,25), new Point(30,35)};

// myPointArray[0] becomes (475, 680).
// myPointArray[1] becomes (700, 1030).
myMatrix.Transform(myPointArray);

//
// Transform a vector.
//
Vector myVector = new Vector(15,25);

// vectorResult becomes (450, 650).
Vector vectorResult = myMatrix.Transform(myVector);

//
// Transform an array of vectors.
//
Vector[] myVectorArray = new Vector[]
{new Vector(15, 25), new Vector(30,35)};

// myVectorArray[0] becomes (450, 650).
// myVectorArray[1] becomes (675, 1000).
myMatrix.Transform(myVectorArray);

}
```

#### 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.

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

## Platforms

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.

## Version Information

#### .NET Framework

Supported in: 3.5, 3.0