Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RotateTransform class

Applies to Windows and Windows Phone

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

Inheritance

Object
  DependencyObject
    GeneralTransform
      Transform
        RotateTransform

Syntax


public sealed class RotateTransform : Transform


<RotateTransform .../>

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The RotateTransform class has these types of members:

Constructors

The RotateTransform class has these constructors.

ConstructorDescription
RotateTransform Initializes a new instance of the RotateTransform class.

 

Methods

The RotateTransform class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
TransformBounds Transforms the specified bounding box and returns an axis-aligned bounding box that is exactly large enough to contain it. (Inherited from GeneralTransform)
TransformBoundsCore Provides the means to override the TransformBounds behavior in a derived transform class. (Inherited from GeneralTransform)
TransformPoint Uses this transformation object's logic to transform the specified point, and returns the result. (Inherited from GeneralTransform)
TryTransform Attempts to transform the specified point and returns a value that indicates whether the transformation was successful. (Inherited from GeneralTransform)
TryTransformCore Provides the means to override the TryTransform behavior in a derived transform class. (Inherited from GeneralTransform)

 

Properties

The RotateTransform class has these properties.

PropertyAccess typeDescription

Angle

Read/writeGets or sets the angle, in degrees, of clockwise rotation.

AngleProperty

Read-onlyIdentifies the Angle dependency property.

CenterX

Read/writeGets or sets the x-coordinate of the rotation center point for this transformation.

CenterXProperty

Read-onlyIdentifies the CenterX dependency property.

CenterY

Read/writeGets or sets the y-coordinate of the rotation center point for this transformation.

CenterYProperty

Read-onlyIdentifies the CenterY dependency property.

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)

Inverse

Read-onlyGets the inverse transformation of this GeneralTransform, if possible. (Inherited from GeneralTransform)

InverseCore

Read-onlyImplements the behavior for return value of Inverse in a derived or custom GeneralTransform. (Inherited from GeneralTransform)

 

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:

  • 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>


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Media
Windows::UI::Xaml::Media [C++]

Metadata

Windows.winmd

See also

XAML two-dimensional transforms sample
Transform

 

 

Show:
© 2014 Microsoft