none
Rendertransform and TranslatePoint/TransformToVisual RRS feed

  • Question

  • I just recently figured out that setting the RenderTransform Property and using TranslatePoint in a loop is problematic. Somehow assigning a new Transformation object onto RenderTransform has no effect on TranslatePoint.

    I tested this behaviour with following code: (I know .. assigning a new Transformation object every time is not very performant)

    for(int i = 0; i < 100; ++i) 
         // get the current transformation 
         TranslateTransform t = (TranslateTransform)TestCanvas.RenderTransform; 
         
         // translate a (0,0) point to my GoalCanvas 
         Point p = TestCanvas.TranslatePoint(new Point(0,0), GoalCanvas); 
         // trace that point 
         Trace.Writeline(p); 
         
         // increase translation 
         ++t.X; 
     
         // assign it to the RenderTransform 
         TestCanvas.RenderTransform = t; 


    Interestingly Point p is always (0,0).

    To make that code work correctly, I have to create an TranslaleTransform object and assign it to RenderTransform in advance and have to avoid to set the RenderTransform directly in the loop.

    I assume that the transformation-information in the visual tree is not instantly updated when a new transformation object was added.
    But, Why is that? Is this behaviour intended?

    Tuesday, July 29, 2008 8:06 AM

Answers

  • Transforms are not really applied to the visual tree until a measure/arrange cycle has happened. You could probably force this by calling UpdateLayout, but why would you want to? This requirement does not make a lot of sense.

    I can see why it would work if you assign the transforms first: they are updated into the visual tree, and then subsequently changing their values, while still having no effect on the visual tree until a paint cycle, would probably be instantly reflected in a TranslatePoint call.
    Controls for WPF and Windows Forms at http://www.divelements.co.uk
    • Marked as answer by Marco Zhou Monday, August 4, 2008 9:47 AM
    Tuesday, July 29, 2008 2:15 PM