SIGN UP MEMBER LOGIN:    
ARTICLE

Applying Multiple Transformations using the TransformGroup in Silverlight 2.0

Posted by Dipal Choksi Articles | Silverlight with C# January 22, 2009
In this article we will see how to apply multiple transformations to a single object in Silverlight 2.0 using the TransformGroup class.
Reader Level:

In this article we will see how to apply multiple transformations to a single object in Silverlight 2.0 using the TransformGroup class.

 

Multiple transformations can be specified for the same object by including them within the TransformGroup. In the following example, we will display a Rectangle object which undergoes 2 transformations - a RotateTranform and a SkewTransform.

 

<Rectangle x:Name="rectTransform1" Width="50" Height="50" Fill="Blue">

<Rectangle.RenderTransform>

<TransformGroup>

<RotateTransform Angle="45"></RotateTransform>

<SkewTransform AngleX="10"></SkewTransform>

</TransformGroup>

</Rectangle.RenderTransform>

</Rectangle>

 

 

Image: The Rectangle object is subjected to the composite transformation using the TranformGroup object

 

The order of the transformations is important and can impact the results. In the following example, we add another Rectangle object, with the same transformations applied in reverse order. Note how the end results vary based on the sequencing.

 

<Grid x:Name="mainGrid" ShowGridLines="True">

<Grid.RowDefinitions>

<RowDefinition/>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition/>

<ColumnDefinition/>

</Grid.ColumnDefinitions>

<Rectangle  Grid.Row="0" Grid.Column="0"  x:Name="rectTransform1" Width="50" Height="50" Fill="Blue">

<Rectangle.RenderTransform>

<TransformGroup>

<RotateTransform Angle="45"></RotateTransform>

<SkewTransform AngleX="10"></SkewTransform>

</TransformGroup>

</Rectangle.RenderTransform>

</Rectangle>

<Rectangle  Grid.Row="0" Grid.Column="1"  x:Name="rectTransform2" Width="50" Height="50" Fill="Blue" >

<Rectangle.RenderTransform>

<TransformGroup>

<SkewTransform AngleX="10"></SkewTransform>

<RotateTransform Angle="45"></RotateTransform>

</TransformGroup>

</Rectangle.RenderTransform>
</
Rectangle>

</Grid>

 

 

Image: Order of sequencing for Transforms

 

The TransformGroup class has the Children property which provides the content Child Transform objects and the Value property which represents the transformation result using a Matrix object. A TranformGroup can contain nested TransformGroups. One of the scenarios where nested TranformGroups could be useful is when you have an existing TransformGroup collection specified on an object and would like to add additional transformations along with allowing the user to save the existing TranformGroup.

 

Conclusion:

 

In this sample, we demonstrated the use of the TransformGroup object to specify multiple transformations and observed the impact of sequencing of transformations on the result.

 

Happy Coding! 

 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor