RotateTransform RotateTransform RotateTransform RotateTransform Class

Definition

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

public : sealed class RotateTransform : Transform, IRotateTransformpublic sealed class RotateTransform : Transform, IRotateTransformPublic NotInheritable Class RotateTransform Inherits Transform Implements IRotateTransform// This API is not available in Javascript.
<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.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)Windows.UI.Xaml.Media.GeneralTransform.TryTransformCore(Windows.Foundation.Point,Windows.Foundation.Point)

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>

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 UIElement.RenderTransform property, to change how an element renders. UIElement also has the UIElement.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 UIElement.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 UIElement.RenderTransformOrigin to be a logical Point where the values are (0.5,0.5). Using the logical point convention, that puts the UIElement.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.

UIElement.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 Canvas.Left and Canvas.Top, 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:

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();
}

Constructors

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

Initializes a new instance of the RotateTransform class.

public : RotateTransform()public RotateTransform()Public Sub New()// This API is not available in Javascript.

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 double// This API is not available in Javascript.
<RotateTransform Angle="double"/>
Value
double double double double

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

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 DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the Angle dependency property.

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 double// This API is not available in Javascript.
<RotateTransform CenterX="double"/>
Value
double double double double

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

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 DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the CenterX dependency property.

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 double// This API is not available in Javascript.
<RotateTransform CenterY="double"/>
Value
double double double double

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

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 DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the CenterY dependency property.

See Also