【问题标题】:WPF RotateTransform question on offset关于偏移量的 WPF RotateTransform 问题
【发布时间】:2011-03-13 22:02:39
【问题描述】:

如下:

<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 设置为矩形大小的一半。有没有办法在标记中做到这一点?

类似 CenterX="{Binding Path=Width\2}" 的东西?

【问题讨论】:

    标签: wpf rotatetransform


    【解决方案1】:

    您可以在Rectangle 本身上设置RenderTrasformOrigin 属性:

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

    【讨论】:

    • 优秀。我知道这会是直截了当的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    相关资源
    最近更新 更多