Access a Canvas's ScaleTransform ScaleX property via Script?

I need to access and change the ScaleX property of a ScaleTransform object but can't seem to find the trick to getting to it with script. I've tried the following and a few variations:

var cToMove = albumCanvases.GetItem(i);
alert(cToMove.RenderTransform.ScaleTransform.ScaleX);

If anyone could explain how to access the property via script I'd really appreciate it. The XAML for the ScaleTransform is below (I'm creating it dynamically which is why the placeholders are in there):

<Canvas.RenderTransform>

<ScaleTransformScaleX='{7}'ScaleY='{7}'CenterX='0'CenterY='0' />

</Canvas.RenderTransform>

[1805 byte] By [DanWahlin] at [2008-2-15]
«« Textbox
»» How do I
# 1

If you're add this with script (with createFromXaml), you need to add the namespace declarations to the top of the XAML fragment. Then you can specify an x:Name to the ScaleTransform. If you do this you can:

var tx = host.findName("myTxName");

var scaleX = tx.scaleX;

Currently the RenderTransforms do not support iterating through their children. This might be fixed later, but currently if you have more than one of these transforms (like on a child object), the work around is to name them:

<Canvas.RenderTransform>

<ScaleTransform x:Name="someObject%8" ... />

</Canvas.RenderTransform>

Then you can get it something like this:

var cToMove = albumCanvases.GetItem(i);
var tx = cToMove.findName(cToMove.Name + i);

alert(tx.ScaleX);

ShawnWildermuth-MVP at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...
# 2
Thanks.....I'll give that a shot. Accessing it by name makes sense although in a future build I hope we'll be able to access these types of things directly in script to keep it simple.
DanWahlin at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...
# 3

In your scenario above, you should actually be able to do:

alert(myRectangle.RenderTransform.ScaleX);

This is because you only have a single Transform attached to the RenderTransform property. Please note the syntax "myRectangle.RenderTransform.ScaleTransform.ScaleX" is incorrect, since RenderTransform _is_ of type ScaleTransform; it doesn't have a ScaleTransform property.

To be precise about what is not supported on the Dec CTP, it is iterating over the Children of a TransformGroup. For example, you could not get the ScaleX property on the following ScaleTransform without giving it a Name:

<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.8" ScaleY="0.8"/>
<TransformGroup>
</Rectangle.RenderTransform>

Hope this helps.

Ed Maia
WPF/E PM

EdMaiaMSFT at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...
# 4
That helps a lot...thanks for posting the information. I didn't realize that RenderTransform was of type ScaleTransform but that makes sense.
DanWahlin at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...