Search code examples
wpfoffsetrotatetransformrendertransform

wpf rotatetransform -- How do I get my control position back to normal?


Basically, I rotated an item:

<Button Content="HelloWorld">
    <Button.RenderTransform>
        <RotateTransform Angle="270" />
    </Button.RenderTransform>
</Button>

How do I get it so that it moves down. Right now it sticks straight up since I rotated it around the 0,0 point. I need it so that the 0,0 point moves down so that the top is where the original top was.


Solution

  • Add a TranslateTransform:

    <Button x:Name="MyButton" Content="HelloWorld">
        <Button.RenderTransform>
            <TransformGroup>
                <RotateTransform Angle="270" />
                <TranslateTransform Y="{Binding ActualWidth, ElementName=MyButton}" />
            </TransformGroup>
        </Button.RenderTransform>
    </Button>