Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF RotateTransform question on offset

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 on its centre I have to set the CenterX and Y to half of the Rectangle's size. Is there a way to do that in markup?

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

like image 642
Ian Avatar asked Dec 16 '22 16:12

Ian


1 Answers

You can set RenderTrasformOrigin property on the Rectangle itself:

<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>
like image 155
Pavlo Glazkov Avatar answered Jan 05 '23 23:01

Pavlo Glazkov