开发者

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>
开发者_StackOverflow

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜