Make ScaleTransform start from Center instead of Top-Left Corner

后端 未结 2 1143
长情又很酷
长情又很酷 2021-02-06 21:54

I have the following Style for a Button which is supposed to grow to 1.5 times the size when the mouse hovers it. The problem is that Button grows from the Top-Left corner inste

相关标签:
2条回答
  • 2021-02-06 22:30

    You can set RenderTransformOrigin to "0.5, 0.5"

    <Style x:Key="sizeButton" TargetType="Button">
        <Setter Property="RenderTransformOrigin" Value="0.5, 0.5"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    0 讨论(0)
  • 2021-02-06 22:39

    ScaleTransform.CenterX and ScaleTransform.CenterY are not values between [0, 1], rather they should be absolute pixel values.

    <ScaleTransform CenterX="50" CenterY="25" ScaleX="1.5" ScaleY="1.5"/>
    
    0 讨论(0)
提交回复
热议问题