#773 – A Rotation Center Point Can Be Outside an Element
March 11, 2013 Leave a comment
When you use the RenderTransformOrigin property of an element to specify the point of origin for all render transforms, you typically express X and Y as normalized coordinates. X and Y both range from 0.0 to 1.0 as the position moves from one side of the element to the other.
You can also specify X and Y values that are less than 0.0 or greater than 1.0, indicating a point that is outside the element’s boundaries. (Possibly quite distant from the element).
In the example below, the origin for a rotation transform is set to be off to the right of a Button. The Slider allows you to try out different rotation angles at runtime.
<StackPanel Orientation="Vertical"> <Button Content="Push Me" HorizontalAlignment="Center" Padding="10,5" Margin="5"/> <Button Content="And Me" HorizontalAlignment="Center" Padding="10,5" Margin="5" RenderTransformOrigin="3.0,1.0" > <Button.RenderTransform> <RotateTransform Angle="{Binding ElementName=sliAngle, Path=Value}" /> </Button.RenderTransform> </Button> <Slider Name="sliAngle" Minimum="-180" Maximum="180" Value="-20" Margin="25,100"/> </StackPanel>