开发者

WPF RotateTransform question on offset

开发者 https://www.devze.com 2023-02-17 01:38 出处:网络
In the following: <Rectangle Height=\"60\" HorizontalAlignment=\"Left\" Margin=\"50,100,0,0\" Name=\"rectangle2\" Stroke=\"Black\" VerticalAlignment=\"Top\" Width=\"60\" >

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

精彩评论

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

关注公众号