Dot Net For All

LayoutTransform and RenderTransform in WPF

Understanding Tranformation(LayoutTransform and RenderTranformation)

Transformation helps us to map points of a particular shape or element from one coordinate space to another coordinate space. There can be many cases where we want to incorporate some animations in the WPF application. These animations can be incorporated with the help of transformations.

A transformation can be used on an element to

And to achieve all these functionalities WPF class system provided the following classes –

 

As we can see from the above figure that all the transforms inherit from the Transform Class of WPF system. I will discuss all these transforms individually in the next article. But in this article I want to discuss the LayoutTransform and RenderTransform Classes of the WPF.

Both the LayoutTransform and RenderTransform are of type Transform.All the different type of transforms which we have discussed earlier can be applied to both of these transforms

Origin of Render Transform 

As the render transform occurs after the layout process, that is why it needs origin for the element to take place. It happens with the help of the RenderTransformOrigin property whose default property is (0,0) and it is relative to the size of the element as shown in the figure below

 

As seen from the above figure if I want to rotate my element with relative to its centre I have to assign the values 0.5,0.5 to its render transform origin property.

<TextBlock Width="200" Background="Gray" Text="LayoutTransform" RenderTransformOrigin=".5,.5">
                <TextBlock.RenderTransform>
                    <RotateTransform Angle="20"></RotateTransform>
                </TextBlock.RenderTransform>
            </TextBlock>

And the output of the above code snippet is as shown below

In this article I have explained the two types of transformations and their utilization s.

 

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview