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>
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);
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