以下内容:
<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}”之类的东西?
答案 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>