Delay's Blog is the blog of David Anson, a Microsoft developer who works with the Silverlight, WPF, Windows Phone, and web platforms.
http://dlaa.me/
@DavidAns
In the introductory post for LayoutTransformControl, I showed a trivial use case to demonstrate the need for LayoutTransform in some scenarios. I also noted that Silverlight 2 supports only RenderTransform, but went on to demonstrate how it was possible to use RenderTransform to get LayoutTransform behavior. I described how my LayoutTransformControl sample did just that, but implemented only RotateTransform functionality for its initial release. My impression then - as now - is that rotation is easily the most common use of LayoutTransform. However, there are plenty of scenarios where the other Transform subclasses (scale, skew, matrix, etc.) are required, and I wanted to have a solution for them as well.
So I've added full support for arbitrary transformations to LayoutTransformControl along with updating it for Beta 2! (The complete implementation - along with demo and test applications - can be found in LayoutTransformControl.cs in the attached ZIP.)
Where you might previously have written:
<local:LayoutTransformControl Angle="15"> <TextBlock Text="I am rotated 15 degrees!"/> </local:LayoutTransformControl>
You now write:
<local:LayoutTransformControl> <local:LayoutTransformControl.Transform> <RotateTransform Angle="15"/> </local:LayoutTransformControl.Transform> <TextBlock Text="I am rotated 15 degrees!"/> </local:LayoutTransformControl>
Wait a second! That's more typing than before - why is this an improvement? Well, because you can also do this (just as you would on WPF):
<local:LayoutTransformControl> <local:LayoutTransformControl.Transform> <ScaleTransform ScaleX="1.5" ScaleY="2.5"/> </local:LayoutTransformControl.Transform> <TextBlock Text="I am a little wider and a lot taller!"/> </local:LayoutTransformControl>
Or this:
<local:LayoutTransformControl> <local:LayoutTransformControl.Transform> <MatrixTransform Matrix="-1,0,0,1,0,0"/> </local:LayoutTransformControl.Transform> <TextBlock Text="I am flipped horizontally!"/> </local:LayoutTransformControl>
Or even this:
<local:LayoutTransformControl> <local:LayoutTransformControl.Transform> <TransformGroup> <ScaleTransform ScaleX="1.5" ScaleY="2.5"/> <SkewTransform AngleX="10"/> <MatrixTransform Matrix="-1,0,0,1,0,0"/> <RotateTransform Angle="15"/> </TransformGroup> </local:LayoutTransformControl.Transform> <TextBlock Text="I am all of the above - and tilted, too!!"/> </local:LayoutTransformControl>
So maybe it's a bit of an improvement, after all... :)
Naturally, I updated my sample application to show off the new capabilities:
And I updated my cross-platform test suite as well (here's the WPF version):
LayoutTransformControl should now be just as powerful as WPF's LayoutTransform is. Your application can take advantage of complete LayoutTransform functionality today - even though the Silverlight platform still doesn't officially support LayoutTransform!
Notes:
The examples above assume the "local" namespace prefix has been mapped to an assembly containing the LayoutTransformControl implementation:
xmlns:local="clr-namespace:LayoutTransformControlSample;assembly=YourAssemblyName"
My goal with LayoutTransformControl has always been to address a perceived need. It began life as a bit of an experiment, but by now I've become rather fond of the solution and plan to incorporate it into projects of my own. I hope that if you have a need for LayoutTransform behavior in Silverlight, you'll consider LayoutTransformControl, too!