views:

274

answers:

1

Hello everyone,

I am using Silverlight 3.0 + C# + VSTS 2008 + .Net 3.5. I am learning from the following tutorial about TranslateTransform.

http://vbcity.com/blogs/canoz/archive/2010/05/02/beginning-silverlight-translatetransform.aspx

My question is how RenderTransformOrigin works together with TranslateTransform to achieve visual effect? My question is from the following section -- section "3. Resizable element and RenderTransformOrigin."

thanks in advance, George

+2  A: 

The result of a translate transform are unaffected by the RenderTransformOrigin.

If you specify that an element should be translated right by 200 px it really doesn't matter where the origin is currently located.

Example

If you have a rectangle of width 100 and you were to specify the x portion of RenderTransformOrigin` to be 0.5. The origin in x will be 50 pixels into the rectangle (the center) and the location of the left edge relative to the origin will be -50.

If you Translate that in X by 100 the left edge will now be at 50 relative to the origin. Since the origin itself was already at 50 the total distance the left edge will have moved from its original position would be (50 + 50) 100 as you'd expect.

Now change only the RenderTransformOrigin from 0.5 to -0.5. Now the origin will be 50 pixels to the left of the left edge of the rectangle (that is it will be -at 50). The location of left edge of the rectangle relative to the origin will be 50. When translated to its new position it will be at 150 relative to the origin. The total distance the rectangle would have moved from its original position would be (-50 + 150) 100 again as you'd expect.

AnthonyWJones
"The result of a translate transform are unaffected by the RenderTransformOrigin." -- do you mean the document is wrong?
George2
"and the location of the left edge relative to the origin will be -50." -- when you mention left edge, do you mean left edge of the rectangle element itself, or the left edge of area which the rectangle resides in (e.g. the parent canvas container of the rectangle element)?
George2
@George: The document is just a little confused. Its discussing the translate transfrom which does not involve any "resizing". The basic idea is correct it just doesn't belong in that document since its only relevant to the other transforms such as Scale.
AnthonyWJones
The left edge of the rectangle element before its transformed.
AnthonyWJones
Thanks! I am confused about this comment -- "If you Translate that in X by 100 the left edge will now be at 50 relative to the origin.". If you mean TranslateTransform X="100", then I think it should be 100 relative to the origin, why only 50?
George2
@George2: Because the left hand edge started at -50 relative to the origin. -50 + 100 = 50.
AnthonyWJones
Sorry @AnthonyWJones, I think it should not be -50 + 100 = 50, but -50 + (-100) = -150. I draw the effect here, could you comment and correct me if I am wrong. Thank you!http://i47.tinypic.com/348iof8.pnghttp://i48.tinypic.com/50jy9e.png
George2
@AnthonyWJones, any ideas for my update comments above?
George2
@George2: I'm standing in my front door of my house facing in, behind me 30 metres away is the house opposite. I choose my front door to be the origin, I'm currently at position 0. I translate down the hallway 3 metres, where am I now? 3 metres relative to the origin. Reset, I'm back in the doorway. I choose the opposite house to be the orgin, I am at position 30. I translate down the hallway 3 metres, where am I now? 33 metres relative to the origin. Am I standing in a different place than in previous transform. __No__. The point chosen as the origin has no impact on the results.
AnthonyWJones
You mean in your sample of RenderTransformOrigin, you use different origin? Could you explain in more details please? :-)
George2
Thanks, question answered!
George2