0

While implementing IScrollInfo's MakeVisible member, I ran into an issue. I need to get the coordinates of that Visual's bounds relative to the panel which is being scrolled.

Now if this were a UIElement, this would be easy as I'd just call its 'TranslatePoint' method, but UIElement is a subclass of Visual, not the other way around, so I can't necessarily count on that.

How would one go about achieving this?

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286

1 Answers1

1

Visual provides the TransformToVisual method, which returns a GeneralTransform that can be used to transform points or rectangles:

var transform = visual1.TransformToVisual(visual2);
var point = transform.Transform(new Point(...));

If visual1 is a ContainerVisual, you can do this:

var bounds = transform.TransformBounds(visual1.ContentBounds);

or

var bounds = transform.TransformBounds(visual1.DescendantBounds);
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • Perfect! Exactly what I was looking for. Thanks! I used the TransformBounds directly with the rectangle passed in to the IScrollInfo.MakeVisible call, and that worked great! – Mark A. Donohoe Dec 20 '12 at 20:44