* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.7 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|
| How to: Rotate an Object | 03/30/2017 |
|
|
ee3466cd-e66f-4e8f-8a5a-71d77bc1e390 |
How to: Rotate an Object
This example shows how to rotate an object. The example first creates a xref:System.Windows.Media.RotateTransform and then specifies its xref:System.Windows.Media.RotateTransform.Angle%2A in degrees.
The following example rotates a xref:System.Windows.Shapes.Polyline object 45 degrees about its upper-left corner.
Example
[!code-xamlTransforms_snip#RotatePolylineAboutTopLeft]
[!code-csharpTransforms_Procedural_snip#RotatePolylineAboutTopLeft] [!code-vbTransforms_Procedural_snip#RotatePolylineAboutTopLeft]
The xref:System.Windows.Media.RotateTransform.CenterX%2A and xref:System.Windows.Media.RotateTransform.CenterY%2A properties of the xref:System.Windows.Media.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 xref:System.Windows.Shapes.Polyline object clockwise 45 degrees about the point (25,50).
[!code-xamlTransforms_snip#RotatePolylineAboutCenter]
[!code-csharpTransforms_Procedural_snip#RotatePolylineAboutCenter] [!code-vbTransforms_Procedural_snip#RotatePolylineAboutCenter]
The following illustration shows the results of applying a xref:System.Windows.Media.Transform to the two objects.

Two objects that rotate 45 degrees from different rotational centers
The xref:System.Windows.Shapes.Polyline in the previous examples is a xref:System.Windows.UIElement. When you apply a xref:System.Windows.Media.Transform to the xref:System.Windows.UIElement.RenderTransform%2A property of a xref:System.Windows.UIElement, you can use the xref:System.Windows.UIElement.RenderTransformOrigin%2A property to specify an origin for every xref:System.Windows.Media.Transform that you apply to the element. Because the xref:System.Windows.UIElement.RenderTransformOrigin%2A 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 Specify the Origin of a Transform by Using Relative Values.
For the complete sample, see 2D Transforms Sample.