Ian
Ian

Reputation: 4919

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}" ?

Upvotes: 4

Views: 3167

Answers (1)

Pavlo Glazkov
Pavlo Glazkov

Reputation: 20756

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>

Upvotes: 12

Related Questions