WPF RotateTransform Offset Question

In the following:

<Rectangle Height="60" HorizontalAlignment="Left" Margin="50,100,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="60" > <Rectangle.RenderTransform> <TransformGroup> <RotateTransform Angle="45" CenterX="30" CenterY="30"/> </TransformGroup> </Rectangle.RenderTransform> 

To rotate the rectangle in its center, I have to set CenterX and Y to half the size of the rectangle. Is there a way to do this in markup?

Something like CenterX = "{Binding Path = Width \ 2}"?

+4
source share
1 answer

You can set the RenderTrasformOrigin property directly to the Rectangle :

 <Rectangle Height="60" HorizontalAlignment="Left" Margin="50,100,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="60" RenderTrasformOrigin="0.5,0.5"> <Rectangle.RenderTransform> <TransformGroup> <RotateTransform Angle="45" /> </TransformGroup> </Rectangle.RenderTransform> 
+12
source

Source: https://habr.com/ru/post/1343561/


All Articles