Sdílet prostřednictvím


MatrixTransform Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.Windows.DependencyObject
    System.Windows.Media.GeneralTransform
      System.Windows.Media.Transform
        System.Windows.Media.MatrixTransform

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public NotInheritable Class MatrixTransform _
    Inherits Transform
public sealed class MatrixTransform : Transform
<MatrixTransform .../>
<object property="m11, m12, m21, m22, offsetX, offsetY"/>
- or -
<object property="Identity"/>

XAML Values

  • m11
    The value at position (1, 1) of the transformation Matrix.

  • m12
    The value at position (1, 2) of the transformation Matrix.

  • m21
    The value at position (2, 1) of the transformation Matrix.

  • m22
    The value at position (2, 2) of the transformation Matrix.

  • offsetX
    The value at position (3, 1) of the transformation Matrix.

  • offsetY
    The value at position (3, 2) of the transformation Matrix.

The MatrixTransform type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone MatrixTransform Initializes a new instance of the MatrixTransform class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Dispatcher Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Public propertySupported by Silverlight for Windows Phone Inverse Gets the inverse of this transform, if it exists. (Inherited from Transform.)
Public propertySupported by Silverlight for Windows Phone Matrix Gets or sets the Matrix that defines this transformation.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone CheckAccess Determines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetAnimationBaseValue Returns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone Transform Transforms the specified point and returns the result. (Inherited from GeneralTransform.)
Public methodSupported by Silverlight for Windows Phone TransformBounds Transforms the specified bounding box and returns an axis-aligned bounding box that is exactly large enough to contain it. (Inherited from Transform.)
Public methodSupported by Silverlight for Windows Phone TryTransform Attempts to transform the specified point and returns a value that indicates whether the transformation was successful. (Inherited from Transform.)

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows Phone MatrixProperty Identifies the Matrix dependency property.

Top

Remarks

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

A two-dimensional x-y plane uses a 3 x 3 matrix for transformations. You can multiply affine matrix transformations to form linear transformations, such as rotation and skew (shear) transformations 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.

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)

You can offset the local (0,0) position for an object on a Canvas by using the Canvas.Left and Canvas.Top properties, but this does not operate as a transform; the object retains its own local (0,0) position in this case for transform purposes. For details on this concept, see Silverlight Layout System.

Multiple transforms can be applied with a TransformGroup.

Examples

The following example transforms the position and skew of a rectangle using a MatrixTransform.

Run this sample

<Rectangle Width="60" Height="60" Fill="Blue">
  <Rectangle.RenderTransform>
    <MatrixTransform>
      <MatrixTransform.Matrix >

        <!-- This matrix transforms the x,y position of
             the rectangle and skews it. -->
        <Matrix OffsetX="30" OffsetY="100" M12="0.5" />
      </MatrixTransform.Matrix>
    </MatrixTransform>
  </Rectangle.RenderTransform>

</Rectangle>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

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

See Also

Reference

Other Resources