Thursday, February 25, 2010

When arranging visuals, you need to specify a location and size.

Getting the size of a visual (that has already been measured, arranged and rendered) is easy; myVisual.RenderSize. Getting the location isn't quite as obvious; you have to use the TransformToAncestor(Visual) or VisualTreeHelper.GetOffset(myVisual) (which an extension method would help). Either way it doesn't quite seem right.

I've decided that visuals will be arranged to (0, 0) and a TranslateTransform will be applied to position them. Getting the location is no harder than before, and animating the position of the visuals is done through the transform. Managing the transforms will be a little tricky since all transforms applied to a visual (translates, scales etc) must be inside a TransformGroup transform. Objects that manipulate this group can't step on each others' toes.

I don't seem to have much luck with the LayoutTransform property, only RenderTransform. Maybe there's a bug somewhere...

I just found out that "A TranslateTransform in a LayoutTransform has no effect". There's your problem. I could apply a scaleTransform in layout and translate in render.

Nope, that failed (weird behaviour). LayoutTransform seems to be more trouble than its worth. Putting scale and translate into a groupTransform in RenderTransform works, so I'll throw some properties to get/set them in child panel.

To change the value of a dependencyProperty that has been animated (such as TranslateTransform.XProperty), you have to clear the animation by "animating" the property again with a null animation. Calling ClearValue() or SetCurrentValue() don't work.

No comments:

Post a Comment