--- title: "Transforms Overview" ms.date: "03/30/2017" helpviewer_keywords: - "transformations [WPF], about transformations" - "classes [WPF], 2D transform" - "transform classes [WPF], 2D" - "2D transform classes" - "FrameworkElement objects [WPF], rotating" - "FrameworkElement objects [WPF], skewing" - "FrameworkElement objects [WPF], translating" - "Transforms [WPF], about Transforms" - "FrameworkElement objects [WPF], scaling" ms.assetid: 8f153d5e-ed61-4aa5-a7cd-286f0c427a13 --- # Transforms Overview This topic describes how to use the 2D classes to rotate, scale, move (translate), and skew objects. ## What Is a Transform? A defines how to map, or transform, points from one coordinate space to another coordinate space. This mapping is described by a transformation , which is a collection of three rows with three columns of values. > [!NOTE] > Windows Presentation Foundation (WPF) uses row-major matrices. Vectors are expressed as row-vectors, not column vectors. The following table shows the structure of a [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] matrix. ### A 2D transformation matrix |||| |-|-|-| |

Default: 1.0|

Default: 0.0|0.0| |

Default: 0.0|

Default: 1.0|0.0| |

Default: 0.0|

Default: 0.0|1.0| By manipulating matrix values, you can rotate, scale, skew, and move (translate) an object. For example, if you change the value in the first column of the third row (the value) to 100, you can use it to move an object 100 units along the x-axis. If you change the value in the second column of the second row to 3, you can use it to stretch an object to three times its current height. If you change both values, you move the object 100 units along the x-axis and stretch its height by a factor of 3. Because Windows Presentation Foundation (WPF) only supports affine transforms, the values in the right column are always 0, 0, 1. Although Windows Presentation Foundation (WPF) enables you to directly manipulate matrix values, it also provides several classes that enable you to transform an object without knowing how the underlying matrix structure is configured. For example, the class enables you to scale an object by setting its and properties, instead of manipulating a transformation matrix. Likewise, the class enables you to rotate an object by just setting its property. ## Transform Classes Windows Presentation Foundation (WPF) provides the following 2D classes for common transformation operations: |Class|Description|Example|Illustration| |-----------|-----------------|-------------|------------------| ||Rotates an element by the specified .|[Rotate an Object](how-to-rotate-an-object.md)|![Rotate illustration](./media/graphicsmm-thumbnails-rotate.png "graphicsmm_thumbnails_rotate")| ||Scales an element by the specified and amounts.|[Scale an Element](how-to-scale-an-element.md)|![Scale illustration](./media/graphicsmm-thumbnails-scale.png "graphicsmm_thumbnails_scale")| ||Skews an element by the specified and amounts.|[Skew an Element](how-to-skew-an-element.md)|![Skew illustration](./media/graphicsmm-thumbnails-skew.png "graphicsmm_thumbnails_skew")| ||Moves (translates) an element by the specified and amounts.|[Translate an Element](how-to-translate-an-element.md)|![Translate illustration](./media/graphicsmm-thumbnails-translate.png "graphicsmm_thumbnails_translate")| For creating more complex transformations, Windows Presentation Foundation (WPF) provides the following two classes: |Class|Description|Example| |-----------|-----------------|-------------| ||Groups multiple objects into a single that you can then apply to transform properties.|[Apply Multiple Transforms to an Object](how-to-apply-multiple-transforms-to-an-object.md)| ||Creates custom transformations that are not provided by the other classes. When you use a , you manipulate a Matrix directly.|[Use a MatrixTransform to Create Custom Transforms](how-to-use-a-matrixtransform-to-create-custom-transforms.md)| Windows Presentation Foundation (WPF) also provides 3D transformations. For more information, see the class. ## Common Transformation Properties One way to transform an object is to declare the appropriate type and apply it to the transformation property of the object. Different types of objects have different types of transformation properties. The following table lists several commonly used Windows Presentation Foundation (WPF) types and their transformation properties. |Type|Transformation properties| |----------|-------------------------------| ||, | ||| ||| ||, | ||| ||| ||| ## Transformations and Coordinate Systems When you transform an object, you do not just transform the object, you transform coordinate space in which that object exists. By default, a transform is centered at the origin of the target object's coordinate system: (0,0). The only exception is ; a has no center properties to set because the translation effect is the same regardless of where it is centered. The following example uses a to rotate a element, a type of , by 45 degrees about its default center, (0, 0). The following illustration shows the effect of the rotation. ![A FrameworkElement rotated 45 degrees about (0,0)](./media/graphicsmm-fe-rotated-about-upperleft-corner.png "graphicsmm_FE_rotated_about_upperleft_corner") A Rectangle element rotated 45 degrees about the point (0,0) [!code-xaml[Transforms_snip#TransformsFERotatedAboutTopLeft](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/CoordinateSystemExample.xaml#transformsferotatedabouttopleft)] By default, the element rotates about its upper-left corner, (0, 0). The , , and classes provide CenterX and CenterY properties that enable you to specify the point at which the transform is applied. The next example also uses a to rotate a element by 45 degrees; however, this time the and properties are set so that the has a center of (25, 25). The following illustration shows the effect of the rotation. ![A Geometry rotated 45 degrees about (25, 25)](./media/graphicsmm-fe-rotated-about-center.png "graphicsmm_FE_rotated_about_center") A Rectangle element rotated 45 degrees about the point (25, 25) [!code-xaml[Transforms_snip#TransformsFERotatedAboutCenter](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/CoordinateSystemExample.xaml#transformsferotatedaboutcenter)] ## Transforming a FrameworkElement To apply transformations to a , create a and apply it to one of the two properties that the class provides: - – A transform that is applied before the layout pass. After the transform is applied, the layout system processes the transformed size and position of the element. - – A transform that modifies the appearance of the element but is applied after the layout pass is complete. By using the property instead of the property, you can obtain performance benefits. Which property should you use? Because of the performance benefits that it provides, use the property whenever possible, especially when you use animated objects. Use the property when scaling, rotating, or skewing and you need the parent of the element to adjust to the transformed size of the element. Note that, when they are used with the property, objects appear to have no effect on elements. That is because the layout system returns the translated element to its original position as part of its processing. For additional information about layout in [!INCLUDE[TLA#tla_winclient](../../../includes/tlasharptla-winclient-md.md)], see [Layout](../advanced/layout.md) overview. ## Example: Rotate a FrameworkElement 45 Degrees The following example uses a to rotate a button clockwise by 45 degrees. The button is contained in a that has two other buttons. By default, a rotates about the point (0, 0). Because the example does not specify a center value, the button rotates about the point (0, 0), which is its upper-left corner. The is applied to the property. The following illustration shows the result of the transformation. ![A button transformed using RenderTransform](./media/graphicsmm-rendertransformwithdefaultcenter.png "graphicsmm_RenderTransformWithDefaultCenter") Clockwise rotation 45 degrees from upper-left corner [!code-xaml[Transforms_snip#GraphicsMMRotateButtonExample1](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/ButtonRotateTransformExample.xaml#graphicsmmrotatebuttonexample1)] The next example also uses a to rotate a button 45 degrees clockwise, but it also sets the of the button to (0.5, 0.5). The value of the property is relative to the size of the button. As a result, the rotation is applied to the center of the button, instead of its upper-left corner. The following illustration shows the result of the transformation. ![A button transformed about its center](./media/graphicsmm-rendertransformrelativecenter.png "graphicsmm_RenderTransformRelativeCenter") Clockwise rotation 45 degrees around center [!code-xaml[Transforms_snip#GraphicsMMRotateButtonExample2](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/ButtonRotateTransformExample.xaml#graphicsmmrotatebuttonexample2)] The following example uses the property instead of the property to rotate the button. This causes the transformation to affect the layout of the button, which triggers a full pass by the layout system. As a result, the button is rotated and then repositioned because its size has changed. The following illustration shows the result of the transformation. ![A button transformed using LayoutTransform](./media/graphicsmm-layouttransform.png "graphicsmm_LayoutTransform") LayoutTransform used to rotate the button [!code-xaml[Transforms_snip#GraphicsMMRotateButtonExample3](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/ButtonRotateTransformExample.xaml#graphicsmmrotatebuttonexample3)] ## Animating Transformations Because they inherit from the class, the classes can be animated. To animate a , apply an animation of a compatible type to the property you want to animate. The following example uses a and a with a to make a spin in place when it is clicked. [!code-xaml[Transforms_snip#GraphicsMMAnimatedRotateButtonExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/Transforms_snip/CS/ButtonAnimatedRotateTransformExample.xaml#graphicsmmanimatedrotatebuttonexamplewholepage)] For the complete sample, see [2D Transforms Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Graphics/2DTransforms). For more information about animations, see the [Animation Overview](animation-overview.md). ## Freezable Features Because it inherits from the class, the class provide several special features: objects can be declared as [resources](/dotnet/desktop-wpf/fundamentals/xaml-resources-define), shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features that are provided by objects, see the [Freezable Objects Overview](../advanced/freezable-objects-overview.md). ## See also - - - [How-to Topics](transformations-how-to-topics.md) - [2D Transforms Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Graphics/2DTransforms)