WPF RotateTransform偏移问题

时间:2011-03-13 22:02:39

标签: wpf rotatetransform

以下内容:

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

要在中心旋转矩形,我必须将CenterX和Y设置为Rectangle大小的一半。有没有办法在标记中做到这一点?

像CenterX =“{Binding Path = Width \ 2}”之类的东西?

1 个答案:

答案 0 :(得分:12)

您可以在RenderTrasformOrigin本身设置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>