1

I tried to change the scale of an Image with

MYIMAGE.RenderTransform.ScaleTransform.ScaleX = 1;

but it didn't work. So my question is how do I change first off the scale but secondly also the Transform methods, or how do I access the different Transformations via code?

1 Answer 1

2

Standard caveats around avoiding code-behind apply (though this kind of code can be super useful when dynamically generating animations).

RenderTransform is a property that holds a single object reference. It could be a ScaleTransform, TranlateTransform or even a TransformGroup. It doesn't have a ScaleTransform property. The simple way of handling your code would be to assume you know it's a ScaleTransform:

((ScaleTransform)MYIMAGE.RenderTransform).ScaleX = 1;

If you don't know what the type is then you would need is/as checks. In the case of a transform group you end up with an array. If you know the scale transform is first then this would work:

((ScaleTransform)((TransformGroup)MYIMAGE.RenderTransform).Children[0]).ScaleX = 1;

A more generic/safe implementation is left as an exercise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.