Transform Class
Defines functionality that enables transformations in a 2-D plane. Transformations include rotation (RotateTransform), scale (ScaleTransform), skew (SkewTransform), and translation (TranslateTransform). This class hierarchy differs from the Matrix structure because it is a class and it supports animation and enumeration semantics.
Namespace: System.Windows.Media
Assembly: PresentationCore (in PresentationCore.dll)
The Transform type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | CanFreeze | Gets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.) |
![]() | DependencyObjectType | Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.) |
![]() | Dispatcher | Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.) |
![]() | HasAnimatedProperties | Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties. (Inherited from Animatable.) |
![]() ![]() | Identity | Gets an identity transform. |
![]() | Inverse | Gets the inverse of this transform, if it exists. (Overrides GeneralTransform.Inverse.) |
![]() | IsFrozen | Gets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.) |
![]() | IsSealed | Gets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.) |
![]() | Value | Gets the current transformation as a Matrix object. |
| Name | Description | |
|---|---|---|
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | CheckAccess | Determines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
![]() | ClearValue(DependencyProperty) | Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.) |
![]() | ClearValue(DependencyPropertyKey) | Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.) |
![]() | Clone | Creates a modifiable copy of this Transform by making deep copies of its values. |
![]() | CloneCore | Makes the instance a clone (deep copy) of the specified Freezable using base (non-animated) property values. (Inherited from Freezable.) |
![]() | CloneCurrentValue | Creates a modifiable clone of this Transform object by making deep copies of its values. This method does not copy resource references, data bindings, or animations, although it does copy their current values. |
![]() | CloneCurrentValueCore | Makes the instance a modifiable clone (deep copy) of the specified Freezable using current property values. (Inherited from Freezable.) |
![]() | CoerceValue | Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.) |
![]() | CreateInstance | Initializes a new instance of the Freezable class. (Inherited from Freezable.) |
![]() | CreateInstanceCore | When implemented in a derived class, creates a new instance of the Freezable derived class. (Inherited from Freezable.) |
![]() | Equals | Determines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | Freeze() | Makes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.) |
![]() | FreezeCore | Makes this Animatable object unmodifiable or determines whether it can be made unmodifiable. (Inherited from Animatable.) |
![]() | GetAnimationBaseValue | Returns the non-animated value of the specified DependencyProperty. (Inherited from Animatable.) |
![]() | GetAsFrozen | Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetAsFrozenCore | Makes the instance a frozen clone of the specified Freezable using base (non-animated) property values. (Inherited from Freezable.) |
![]() | GetCurrentValueAsFrozen | Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetCurrentValueAsFrozenCore | Makes the current instance a frozen clone of the specified Freezable. If the object has animated dependency properties, their current animated values are copied. (Inherited from Freezable.) |
![]() | GetHashCode | Gets a hash code for this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetLocalValueEnumerator | Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.) |
![]() | InvalidateProperty | Re-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | OnChanged | Called when the current Freezable object is modified. (Inherited from Freezable.) |
![]() | OnFreezablePropertyChanged(DependencyObject, DependencyObject) | Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set. (Inherited from Freezable.) |
![]() | OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty) | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. (Inherited from Freezable.) |
![]() | OnPropertyChanged | Overrides the DependencyObject implementation of OnPropertyChanged to also invoke any Changed handlers in response to a changing dependency property of type Freezable. (Inherited from Freezable.) |
![]() ![]() | Parse | Creates a new Transform from the specified string representation of a transformation matrix. |
![]() | ReadLocalValue | Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.) |
![]() | ReadPreamble | Ensures that the Freezable is being accessed from a valid thread. Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties. (Inherited from Freezable.) |
![]() | SetCurrentValue | Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyProperty, Object) | Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyPropertyKey, Object) | Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.) |
![]() | ShouldSerializeProperty | Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.) |
![]() | ToString() | Creates a string representation of this GeneralTransform. (Inherited from GeneralTransform.) |
![]() | ToString(IFormatProvider) | Creates a string representation of this instance, based on the passed IFormatProvider parameter. (Inherited from GeneralTransform.) |
![]() | Transform | Transforms the specified point and returns the result. (Inherited from GeneralTransform.) |
![]() | TransformBounds | Transforms the specified bounding box and returns an axis-aligned bounding box that is exactly large enough to contain it. (Overrides GeneralTransform.TransformBounds(Rect).) |
![]() | TryTransform | Attempts to transform the specified point and returns a value that indicates whether the transformation was successful. (Overrides GeneralTransform.TryTransform(Point, Point).) |
![]() | VerifyAccess | Enforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
![]() | WritePostscript | Raises the Changed event for the Freezable and invokes its OnChanged method. Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties. (Inherited from Freezable.) |
![]() | WritePreamble | Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties. (Inherited from Freezable.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IFormattable.ToString | Formats the value of the current instance using the specified format. (Inherited from GeneralTransform.) |
Use the MatrixTransform class to create custom transformations that are not provided by the RotateTransform, ScaleTransform, SkewTransform, and TranslateTransform classes.
A 2-D x-y plane uses a 3x3 matrix for transformations. You can multiply affine transformation matrices to form linear transformations, such as rotation and skew (shear) that are followed by translation.
An affine transformation matrix 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; they are as follows:
This example shows how to rotate an object. The example first creates a RotateTransform and then specifies its Angle in degrees.
The following example rotates a Polyline object 45 degrees about its upper-left corner.
<Canvas Height="200" Width="200"> <!-- Rotates the Polyline 45 degrees about the point (0,0). --> <Polyline Points="25,25 0,50 25,75 50,50 25,25 25,0" Stroke="Blue" StrokeThickness="10" Canvas.Left="75" Canvas.Top="50"> <Polyline.RenderTransform> <RotateTransform CenterX="0" CenterY="0" Angle="45" /> </Polyline.RenderTransform> </Polyline> </Canvas>
// Create a Polyline. Polyline polyline1 = new Polyline(); polyline1.Points.Add(new Point(25, 25)); polyline1.Points.Add(new Point(0, 50)); polyline1.Points.Add(new Point(25, 75)); polyline1.Points.Add(new Point(50, 50)); polyline1.Points.Add(new Point(25, 25)); polyline1.Points.Add(new Point(25, 0)); polyline1.Stroke = Brushes.Blue; polyline1.StrokeThickness = 10; // Create a RotateTransform to rotate // the Polyline 45 degrees about its // top-left corner. RotateTransform rotateTransform1 = new RotateTransform(45); polyline1.RenderTransform = rotateTransform1; // Create a Canvas to contain the Polyline. Canvas canvas1 = new Canvas(); canvas1.Width = 200; canvas1.Height = 200; Canvas.SetLeft(polyline1, 75); Canvas.SetTop(polyline1, 50); canvas1.Children.Add(polyline1);
The CenterX and CenterY properties of the RotateTransform specify the point about which the object is rotated. This center point is expressed in the coordinate space of the element that is transformed. By default, the rotation is applied to (0,0), which is the upper-left corner of the object to transform.
The next example rotates a Polyline object clockwise 45 degrees about the point (25,50).
<Canvas Height="200" Width="200"> <!-- Rotates the Polyline 45 degrees about the point (25,50). --> <Polyline Points="25,25 0,50 25,75 50,50 25,25 25,0" Stroke="Blue" StrokeThickness="10" Canvas.Left="75" Canvas.Top="50"> <Polyline.RenderTransform> <RotateTransform CenterX="25" CenterY="50" Angle="45" /> </Polyline.RenderTransform> </Polyline> </Canvas>
// Create a Polyline. Polyline polyline2 = new Polyline(); polyline2.Points = polyline1.Points; polyline2.Stroke = Brushes.Blue; polyline2.StrokeThickness = 10; // Create a RotateTransform to rotate // the Polyline 45 degrees about the // point (25,50). RotateTransform rotateTransform2 = new RotateTransform(45); rotateTransform2.CenterX = 25; rotateTransform2.CenterY = 50; polyline2.RenderTransform = rotateTransform2; // Create a Canvas to contain the Polyline. Canvas canvas2 = new Canvas(); canvas2.Width = 200; canvas2.Height = 200; Canvas.SetLeft(polyline2, 75); Canvas.SetTop(polyline2, 50); canvas2.Children.Add(polyline2);
The following illustration shows the results of applying a Transform to the two objects.

The Polyline in the previous examples is a UIElement. When you apply a Transform to the RenderTransform property of a UIElement, you can use the RenderTransformOrigin property to specify an origin for every Transform that you apply to the element. Because the RenderTransformOrigin property uses relative coordinates, you can apply a transformation to the center of the element even if you do not know its size. For more information and for an example, see How to: Specify the Origin of a Transform by Using Relative Values.
For the complete sample, see 2-D Transforms Sample.
More Code
| How to: Scale an Element | This example shows how to use a ScaleTransform to scale an element. |
| How to: Skew an Element | This example shows how to use a SkewTransform to skew an element. A skew, which is also known as a shear, is a transformation that stretches the coordinate space in a non-uniform manner. One typical use of a SkewTransform is for simulating 3-D depth in 2-D objects. |
| How to: Translate an Element | This example shows how to translate (move) an element by using a TranslateTransform. |
| How to: Make an Element Spin in Place | This example shows how to make an element spin by using a RotateTransform and a DoubleAnimation. |
| How to: Transform a Brush | This example shows how to transform Brush objects by using their two transformation properties: RelativeTransform and Transform. |
| How to: Apply a Transform to an Element When an Event Occurs | This example shows how to apply a ScaleTransform when an event occurs. The concept that is shown here is the same that you use for applying other types of transformations. For more information about the available types of transformations, see the Transform class or Transforms Overview. |
| How to: Apply a Transform to a BitmapImage | This example demonstrates how to apply a Transform to a BitmapImage. |
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
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
System.Windows.Media.RotateTransform
System.Windows.Media.ScaleTransform
System.Windows.Media.SkewTransform
System.Windows.Media.TransformGroup
System.Windows.Media.TranslateTransform






