There are times when you want to transform your object in various ways. For example you would like to tilt the object in 45 degree; you would like skew the object or rotate the object. Below are some important transformation example which you can achieve using Silverlight.
Below is a simple example which uses ‘RotateTransform’ to tilt the text at 45 degree. |
<TextBlock HorizontalAlignment="Center"
Text="Text
rotated by 45 degree">
<TextBlock.RenderTransform>
<RotateTransform Angle="45" />
</TextBlock.RenderTransform>
</TextBlock> |
 S
|
Below is a simple example which uses ‘ScaleTransform’ to scale the text to ‘2’. |
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="Text scaled with 2">
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="2"/>
</TextBlock.RenderTransform>
</TextBlock> |

|
Below is a simple example which uses ‘RenderTransform’ to position your text at a particular X and Y position. |
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center" Text="Text
with X/Y values">
<TextBlock.RenderTransform>
<TranslateTransform X="-100" Y="-100"/>
</TextBlock.RenderTransform>
</TextBlock>
|
 |
In case you want skew your object, below is a simple XAML code snippet which skews you rectangle object at 45 degree. |
<Rectangle Fill="Chocolate"
Stroke="Black" Width="100" Height="100">
<Rectangle.RenderTransform>
<SkewTransform AngleX="45"/>
</Rectangle.RenderTransform>
</Rectangle> |

|
There situations when you would like to apply two or more transformation types on an object. In those scenarios you can use ‘TransformGroup’ to apply multiple transformation. Below is a code snippet which shows ‘SkewTransform’ and ‘RotateTransform’ applied in a group to the rectangle object. |
<Rectangle Fill="Chocolate"
Stroke="Black" Width="100" Height="100">
<Rectangle.RenderTransform>
<TransformGroup>
<SkewTransform AngleX="45"/>
<RotateTransform Angle="45"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle> |

|
Asked In: Many Interviews |
Alert Moderator