Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate a canvas using Layout Transform

Tags:

c#

wpf

xaml

I'm trying to rotate this canvas

            <Canvas Canvas.Left="203" Canvas.Top="274" Name="canvas1" Height="0" Width="0" >
                <Rectangle.LayoutTransform>
                    <RotateTransform Angle="-45"/>
                </Rectangle.LayoutTransform>

I want to rotate this canvas but in the same position.. check this imageenter image description here

The left image I dont want to do that.. I need to create the second one.. but always I need to set X, Y values? Or is there another way?

like image 225
Darf Avatar asked Feb 23 '23 02:02

Darf


1 Answers

In WPF, has two properties to support display transformations, LayoutTransform and RenderTransform.Any Transform assigned to LayoutTransform is applied when layout is performed. RenderTransform is applied after layout when rendering is performed.

You need to change the Transformation to RenderTransform

       <Rectangle.RenderTransform>
            <RotateTransform Angle="-45"/>
        </Rectangle.RenderTransform>

You can see the difference between LayoutTransform and RenderTransform.

like image 124
Shebin Avatar answered Feb 25 '23 15:02

Shebin