RotateTransform Class

Definition

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

Equivalent WinUI class: Microsoft.UI.Xaml.Media.RotateTransform.

public ref class RotateTransform sealed : Transform
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.Media.IRotateTransformStatics, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class RotateTransform sealed : Transform
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.Media.IRotateTransformStatics, 65536, "Windows.Foundation.UniversalApiContract")]
class RotateTransform sealed : Transform
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.Media.IRotateTransformStatics), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class RotateTransform : Transform
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.Media.IRotateTransformStatics), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class RotateTransform : Transform
Public NotInheritable Class RotateTransform
Inherits Transform
<RotateTransform .../>
Inheritance
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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:

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

Constructors

RotateTransform()

Initializes a new instance of the RotateTransform class.

Equivalent WinUI constructor: Microsoft.UI.Xaml.Media.RotateTransform.RotateTransform.

Properties

Angle

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

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.Angle.

AngleProperty

Identifies the Angle dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.AngleProperty.

CenterX

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

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.CenterX.

CenterXProperty

Identifies the CenterX dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.CenterXProperty.

CenterY

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

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.CenterY.

CenterYProperty

Identifies the CenterY dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Media.RotateTransform.CenterYProperty.

Dispatcher

Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

Equivalent WinUI property: Microsoft.UI.Xaml.DependencyObject.Dispatcher.

(Inherited from DependencyObject)
Inverse

Gets the inverse transformation of this GeneralTransform, if possible.

Equivalent WinUI property: Microsoft.UI.Xaml.Media.GeneralTransform.Inverse.

(Inherited from GeneralTransform)
InverseCore

Implements the behavior for return value of Inverse in a derived or custom GeneralTransform.

Equivalent WinUI property: Microsoft.UI.Xaml.Media.GeneralTransform.InverseCore.

(Inherited from GeneralTransform)

Methods

ClearValue(DependencyProperty)

Clears the local value of a dependency property.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ClearValue.

(Inherited from DependencyObject)
GetAnimationBaseValue(DependencyProperty)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetAnimationBaseValue.

(Inherited from DependencyObject)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property from a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetValue.

(Inherited from DependencyObject)
ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if a local value is set.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ReadLocalValue.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.RegisterPropertyChangedCallback.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.SetValue.

(Inherited from DependencyObject)
TransformBounds(Rect)

Transforms the specified bounding box and returns an axis-aligned bounding box that is exactly large enough to contain it.

Equivalent WinUI method: Microsoft.UI.Xaml.Media.GeneralTransform.TransformBounds.

(Inherited from GeneralTransform)
TransformBoundsCore(Rect)

Provides the means to override the TransformBounds behavior in a derived transform class.

Equivalent WinUI method: Microsoft.UI.Xaml.Media.GeneralTransform.TransformBoundsCore.

(Inherited from GeneralTransform)
TransformPoint(Point)

Uses this transformation object's logic to transform the specified point, and returns the result.

Equivalent WinUI method: Microsoft.UI.Xaml.Media.GeneralTransform.TransformPoint.

(Inherited from GeneralTransform)
TryTransform(Point, Point)

Attempts to transform the specified point and returns a value that indicates whether the transformation was successful.

Equivalent WinUI method: Microsoft.UI.Xaml.Media.GeneralTransform.TryTransform.

(Inherited from GeneralTransform)
TryTransformCore(Point, Point)

Provides the means to override the TryTransform behavior in a derived transform class.

Equivalent WinUI method: Microsoft.UI.Xaml.Media.GeneralTransform.TryTransformCore.

(Inherited from GeneralTransform)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.UnregisterPropertyChangedCallback.

(Inherited from DependencyObject)

Applies to

See also