IanG on Tap

Ian Griffiths in Weblog Form (RSS 2.0)

Blog Navigation

April (2018)

(1 item)

August (2014)

(1 item)

July (2014)

(5 items)

April (2014)

(1 item)

March (2014)

(1 item)

January (2014)

(2 items)

November (2013)

(2 items)

July (2013)

(4 items)

April (2013)

(1 item)

February (2013)

(6 items)

September (2011)

(2 items)

November (2010)

(4 items)

September (2010)

(1 item)

August (2010)

(4 items)

July (2010)

(2 items)

September (2009)

(1 item)

June (2009)

(1 item)

April (2009)

(1 item)

November (2008)

(1 item)

October (2008)

(1 item)

September (2008)

(1 item)

July (2008)

(1 item)

June (2008)

(1 item)

May (2008)

(2 items)

April (2008)

(2 items)

March (2008)

(5 items)

January (2008)

(3 items)

December (2007)

(1 item)

November (2007)

(1 item)

October (2007)

(1 item)

September (2007)

(3 items)

August (2007)

(1 item)

July (2007)

(1 item)

June (2007)

(2 items)

May (2007)

(8 items)

April (2007)

(2 items)

March (2007)

(7 items)

February (2007)

(2 items)

January (2007)

(2 items)

November (2006)

(1 item)

October (2006)

(2 items)

September (2006)

(1 item)

June (2006)

(2 items)

May (2006)

(4 items)

April (2006)

(1 item)

March (2006)

(5 items)

January (2006)

(1 item)

December (2005)

(3 items)

November (2005)

(2 items)

October (2005)

(2 items)

September (2005)

(8 items)

August (2005)

(7 items)

June (2005)

(3 items)

May (2005)

(7 items)

April (2005)

(6 items)

March (2005)

(1 item)

February (2005)

(2 items)

January (2005)

(5 items)

December (2004)

(5 items)

November (2004)

(7 items)

October (2004)

(3 items)

September (2004)

(7 items)

August (2004)

(16 items)

July (2004)

(10 items)

June (2004)

(27 items)

May (2004)

(15 items)

April (2004)

(15 items)

March (2004)

(13 items)

February (2004)

(16 items)

January (2004)

(15 items)

Blog Home

RSS 2.0

Writing

Programming C# 5.0

Programming WPF

Other Sites

Interact Software

Avalon Beta 1 RC1 - Where's TransformDecorator?

Tuesday 24 May, 2005, 09:54 PM

Microsoft recently released Beta 1 RC1 of Avalon and Indigo. Yay!

A question that seems to have cropped up quite a lot since is: where did TransformDecorator go? People seem to be having trouble finding its replacement. That's because it hasn't simply changed name. There is no equivalent element because the functionality has moved into the LayoutTransform attribute.

This makes things a bit more consistent than before. In the March 2005 CTP, there were two ways of applying a transform: you could apply one that had no effect on the layout system, and one that had an effect on layout. These used an attribute and an element respectively. With the new CTP, both approaches are still available, but they're now both done with attributes: RenderTransform and LayoutTransform.

If you're wondering what the difference is, consider this untransformed markup:

<Grid xmlns="http://schemas.microsoft.com/winfx/avalon/2005">
  <ColumnDefinition />
  <ColumnDefinition />
  <ColumnDefinition />
  <RowDefinition Height="Auto" />

  <Button Grid.Column="0">Hello, world!</Button>
  <Button Grid.Column="1">Hello, world!</Button>
  <Button Grid.Column="2">Hello, world!</Button>
</Grid>

It looks something like this:

Three buttons

Now let's add a transform to the first line:

<Grid xmlns="http://schemas.microsoft.com/winfx/avalon/2005" RenderTransform="scale 2">

Here's the result:

Three buttons cropped by a RenderTransform

The buttons have been cropped. This is because the Grid has arranged the buttons in exactly the same way as it would have done if the transform weren't there, but the results have then been blown up to double size. That's why we only see half of the UI - it has been enlarged to be twice the size of the available space.

Let's try the other kind of transform instead:

<Grid xmlns="http://schemas.microsoft.com/winfx/avalon/2005" LayoutTransform="scale 2">

Here's the result:

Three buttons scaled by a LayoutTransform

Now all three buttons fit. The buttons are double the height but they remain the same width as before. They've been able to double in height because the relevant RowDefinition in the Grid instructs the row to size automatically. (And my window happened to be tall enough to have space for the buttons even at double their normal size.) But the columns are sharing out the space evenly, so it doesn't matter what the scale is - they should all come out the same width - each one third of the total width. So as you can see, the Grid has taken into account the specified transform, but still managed the layout correctly. That's the distinction of LayoutTransform.

When would you ever not want the layout to be adjusted to take the transform into account? (I.e. why do we have the RenderTransform?) Well for one thing, RenderTransform is provided by a slightly lower level of the Avalon framework - it comes from UIElement while LayoutTransform comes from FrameworkElement, so we're looking at different layers of the API here. But even so, there are some cases where you might not want the layout system to adjust to the transform. For example, you might use an animation to perturb an element's transform (e.g. make it wibble in and out) for effect, and it'd be a bit unnerving if the whole UI were to jiggle around, adjusting its layout to fit around the animation, particularly if the point of the animation was to focus the user's attention on just the one element.

Copyright © 2002-2024, Interact Software Ltd. Content by Ian Griffiths. Please direct all Web site inquiries to webmaster@interact-sw.co.uk