Welcome to MSDN Blogs Sign in | Join | Help

An unexceptional layout improvement [Two LayoutTransformControl fixes for Silverlight 2!]

I'd almost finished patting myself on the back for managing to implement WPF's LayoutTransform on Silverlight using just the RenderTransform available on that platform. (Background reading for LayoutTransformControl: Motivation and introduction for Beta 1, Significant enhancements and update for Beta 2, Update for RTW) Yes, everything was peachy - until I was contacted by kind reader Matthew Serbinski with a report of an InvalidOperationException being thrown by Silverlight when using LayoutTransformControl with a ScaleTransform with ScaleY=0... :(

You've probably already recognized ScaleY=0 as something of an edge case for layout: a value which collapses everything into nothingness. I looked into how WPF's LayoutTransform code handled this situation and discovered that it specifically detected circumstances corresponding to a transformation matrix without an inverse - and skipped performing the usual layout computations. My LayoutTransformControl implementation didn't look for this special case, ended up violating one of the rules of the layout system, and triggered the reported exception.

So I added a little bit of code to handle such input the same way WPF does. And while I was at it, I checked to see if maybe there were other special cases that LayoutTransformControl wasn't handling properly... Sure enough, I found one other scenario: that of needing to layout within an container having no width or height. In this case, LayoutTransformControl's behavior wasn't wrong enough to cause an exception (or any visible problem I noticed), but I made a similar tweak for consistency with WPF.

Changes in place, I modified the LayoutTransformControl sample application, its Silverlight test framework, and its WPF test framework to allow setting both ScaleX and ScaleY to 0. (I'd formerly limited ScaleX/ScaleY to positive values which is why I didn't realize there was a problem myself.) Then I spent some time playing around with the test apps: trying all kinds of things and looking for any other anomalous behavior. Nothing turned up, so I updated the LayoutTransformControl source code download and started writing this post... :)

LayoutTransformControl Sample Application

Changes to code always involve a certain amount of risk that a regression will be introduced. Fortunately, the changes here are small, self-contained, and easy to test - so I'm optimistic they won't cause problems for those of you already using LayoutTransformControl in your projects. Of course, if there are any new problems - or existing ones I don't know about yet! - please let me know and I'll look into them as quickly as I can.

Thank you for your help - happy LayoutTransform-ing!

Published Tuesday, November 18, 2008 10:33 AM by Delay
Filed under: ,

Comments

# 2008 November 19 - Links for today « My (almost) Daily Links

# Silverlight Cream for November 19, 2008 -- #432

Wednesday, November 19, 2008 2:18 PM by Community Blogs

In this issue: Bart Czernicki, Martin Mihaylov, Katrien De Graeve, Silverlight SDK, Arturo Toledo, crocusgirl

# Having problems with layout? Switch to Plan B! [LayoutTransformControl scenarios for WPF]

Thursday, November 20, 2008 1:52 PM by Delay's Blog

When I first wrote about adding full LayoutTransform fidelity to Silverlight with my LayoutTransformControl

# A rose by any other name... [LayoutTransformControl on track to ship in the Silverlight Toolkit under the name LayoutTransformer!]

Monday, March 02, 2009 3:40 PM by Delay's Blog

I'm a believer in the power of LayoutTransform - so much so that I wrote a control to graft this capability

# A bit more than meets the eye [Easily animate LayoutTransformer with AnimationMediator!]

Thursday, April 09, 2009 4:04 PM by Delay's Blog

I came across a question on the Silverlight Toolkit support forum yesterday asking how to animate the

Anonymous comments are disabled
 
Page view tracker