
Transformations and Coordinate Systems
When you transform an object, you do not simply transform the object, you transform coordinate space in which that object exists. By default, a transform is centered at the origin of the target object's coordinate system (0,0). The only exception is a TranslateTransform, which has no center properties to set because the translation effect is the same regardless of where it is centered.
The following example uses a RotateTransform to rotate a Rectangle element (a type of UIElement) by 45 degrees about its default center (0,0).
<Grid x:Name="LayoutRoot" Background="White">
<Rectangle Width="50" Height="50"
Fill="RoyalBlue">
<Rectangle.RenderTransform>
<RotateTransform Angle="45" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
The following illustration shows the effect of the rotation.
A Rectangle element rotated 45 degrees about the point (0,0)
.png)
By default, the element rotates about its upper-left corner (0,0). The RotateTransform, ScaleTransform, and SkewTransform classes provide CenterX and CenterY properties that enable you to specify the point at which the transform is applied.
The next example also uses a RotateTransform to rotate a Rectangle element by 45 degrees; however, this time the CenterX and CenterY properties are set so that the RotateTransform has a center of 25,25.
<StackPanel>
<Rectangle Width="50" Height="50" Fill="RoyalBlue">
<Rectangle.RenderTransform>
<RotateTransform Angle="45" CenterX="25" CenterY="25" />
</Rectangle.RenderTransform>
</Rectangle>
</StackPanel>
A Rectangle element rotated 45 degrees about the point (25,25)