RotateTransform RotateTransform RotateTransform Class

Definition

Rotates an object around a specified point in a two-dimensional x-y coordinate system.

public sealed class RotateTransformpublic sealed class RotateTransformPublic NotInheritable Class RotateTransform
<RotateTransform .../>
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited methods

Inherited properties

Windows.UI.Xaml.Media.GeneralTransform.TryTransform(Windows.Foundation.Point,Windows.Foundation.Point)Windows.UI.Xaml.Media.GeneralTransform.TryTransform(Windows.Foundation.Point,Windows.Foundation.Point)Windows.UI.Xaml.Media.GeneralTransform.TryTransform(Windows.Foundation.Point,Windows.Foundation.Point)
Windows.UI.Xaml.Media.GeneralTransform.TryTransformCore(Windows.Foundation.Point,Windows.Foundation.Point)Windows.UI.Xaml.Media.GeneralTransform.TryTransformCore(Windows.Foundation.Point,Windows.Foundation.Point)Windows.UI.Xaml.Media.GeneralTransform.TryTransformCore(Windows.Foundation.Point,Windows.Foundation.Point)

Remarks

A RotateTransform is defined by an Angle that rotates an object through an arc around the point CenterX, CenterY.

If the Angle value applied is positive, the rotation applied is in the clockwise direction. It's legal to use an Angle value that's negative, which causes the rotation to be counterclockwise. For values less than –360 or greater than 360, the values wrap around and are treated as if the mathematical operation mod(360) was applied.

To rotate in place, leave CenterX, CenterY as the default (0,0). You might use a nondefault CenterX, CenterY if you don't want to rotate in place and instead want to rotate around a point in the transform's frame of reference. For example, you can simulate an orbit.

A Transform is typically used to fill the RenderTransform property, to change how an element renders. UIElement also has the RenderTransformOrigin property, which defaults to (0,0). RenderTransformOrigin establishes the coordinate frame of reference for how all transformations including the RotateTransform will apply. A common scenario for RotateTransform is to rotate an object in place around its center (either as an animation or as a one-time transformation). With the default RenderTransformOrigin of (0,0) an object won't rotate around its center, it rotates around the top left corner of its bounding box. Therefore, the common way to cause an object to rotate around its center is to leave CenterX, CenterY as (0,0) but set RenderTransformOrigin to be a logical Point where the values are (0.5,0.5). Using the logical point convention, that puts the RenderTransformOrigin at the center point of the object, in other words at an origin where (x,y) are exactly half of the ActualHeight and ActualWidth values.

RenderTransformOrigin uses the logical point convention; CenterX and CenterY don't use that convention, they use actual pixel values.

The rendering position for an object can be offset on a Canvas using LeftProperty and TopProperty, but this does not count as a transformation; the object retains its own local (0,0) origin when it's positioned in a Canvas.

There are other properties and relationships that can affect how the rotation appears. If there are multiple transformations applied by using a TransformGroup, the order matters. The transformations are applied in the order that they appear in the TransformCollection. Especially if one of the transformations is a TranslateTransform, you might have to alter the order to get the rotation effect you want.

There are three ways to apply multiple transformations to the same object:

  • Using a TransformGroup, where you can specify the order that each transformation applies.
  • Using a CompositeTransform, where each of the transformations is enabled by properties of a shared Transform object and the transformations are applied in a fixed, known order.
  • Using a MatrixTransform, where you set the various properties that control the 3×3 matrix in such a way that you're combining the typical classifications of transformations into one Transform. Unless you're using a design tool to help set the values, this is probably the most advanced technique.

Animating a RotateTransform

You can apply an animation to a RotateTransform to cause an element to rotate over time. Typically you only apply the animation to the Angle property, and don't animate CenterX, CenterY. For a continuously spinning animation, you'd typically use just the To value for a From/To/By style animation. Angle is a Double so this involves a DoubleAnimation. For a continuous animation you'd set the RepeatBehavior of the DoubleAnimation to Forever.

<Page.Resources>
  <Storyboard x:Name="spinrect">
     <DoubleAnimation To="360" RepeatBehavior="Forever" 
         Storyboard.TargetName="spinme"
         Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" />
  </Storyboard>
</Page.Resources>
<StackPanel>
  <Rectangle Name="spinme" Width="50" Height="50" Fill="Red" RenderTransformOrigin=".5,.5"
      PointerPressed="spinme_PointerPressed">
    <Rectangle.RenderTransform>
      <RotateTransform/>
    </Rectangle.RenderTransform>
  </Rectangle>
</StackPanel>
private void spinme_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    spinrect.Begin();
}

Examples

Transforms can alter the display of text in your application to create a decorative effect. This example shows text rotated 90 degrees using a RotateTransform.

This example uses a RotateTransform to rotate text. An Angle value of 90 rotates the element 90 degrees clockwise.

<!-- Rotate the text 90 degrees using a RotateTransform. -->
<TextBlock Text="Rotated Text" FontSize="32" Foreground="Teal">
  <TextBlock.RenderTransform>
    <RotateTransform Angle="90" />
  </TextBlock.RenderTransform>
</TextBlock>

Constructors

RotateTransform() RotateTransform() RotateTransform() RotateTransform()

Initializes a new instance of the RotateTransform class.

public RotateTransform()public New()Public Sub New()public RotateTransform()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

Angle Angle Angle Angle

Gets or sets the angle, in degrees, of clockwise rotation.

public double Angle { get; set; }public double Angle { get; set; }Public ReadWrite Property Angle As doublepublic double Angle { get; set; }
<RotateTransform Angle="double"/>
Value
double double double

The angle, in degrees, of clockwise rotation. The default is 0.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

AngleProperty AngleProperty AngleProperty AngleProperty

Identifies the Angle dependency property.

public static DependencyProperty AngleProperty { get; }public static DependencyProperty AngleProperty { get; }Public Static ReadOnly Property AngleProperty As DependencyPropertypublic static DependencyProperty AngleProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the Angle dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

CenterX CenterX CenterX CenterX

Gets or sets the x-coordinate of the rotation center point for this transformation.

public double CenterX { get; set; }public double CenterX { get; set; }Public ReadWrite Property CenterX As doublepublic double CenterX { get; set; }
<RotateTransform CenterX="double"/>
Value
double double double

The x-coordinate of the center of rotation, in pixels within the transform's frame of reference. The default is 0.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When a RotateTransform is applied as the RenderTransform for a UIElement, the RenderTransformOrigin can also affect how the transformation behaves. In particular this affects the center point that the UIElement rotates around. For more info, see Remarks in RotateTransform.

CenterXProperty CenterXProperty CenterXProperty CenterXProperty

Identifies the CenterX dependency property.

public static DependencyProperty CenterXProperty { get; }public static DependencyProperty CenterXProperty { get; }Public Static ReadOnly Property CenterXProperty As DependencyPropertypublic static DependencyProperty CenterXProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the CenterX dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

CenterY CenterY CenterY CenterY

Gets or sets the y-coordinate of the rotation center point for this transformation.

public double CenterY { get; set; }public double CenterY { get; set; }Public ReadWrite Property CenterY As doublepublic double CenterY { get; set; }
<RotateTransform CenterY="double"/>
Value
double double double

The y-coordinate of the center of rotation, in pixels within the transform's frame of reference. The default is 0.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When a RotateTransform is applied as the RenderTransform for a UIElement, the RenderTransformOrigin can also affect how the transformation behaves. In particular this affects the center point that the UIElement rotates around. For more info, see Remarks in RotateTransform.

CenterYProperty CenterYProperty CenterYProperty CenterYProperty

Identifies the CenterY dependency property.

public static DependencyProperty CenterYProperty { get; }public static DependencyProperty CenterYProperty { get; }Public Static ReadOnly Property CenterYProperty As DependencyPropertypublic static DependencyProperty CenterYProperty { get; }
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the CenterY dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)