tags:

views:

230

answers:

1

Hello,

  1. I have a Viewbox with a Canvas Child,
  2. I have the Stretch property of Viewbox to Fill,
  3. I have changed the width and height of the Viewbox,
  4. I need to get the location of children in Canvas with respect to Viewbox parent I tried :

    Point p = viewboxInstance.TranslatePoint(new Point(Canvas.GetLeft(child), Canvas.GetTop(child)), viewboxInstanceParent);

it gets wrong coordinates! Is there a solution or work around ?

Thanks

A: 

The ViewBox does not change any properties of its children including Canvas left and top values. You need to use the actual coordinates of the child, not just the attached property values.

You can call TranslatePoint directly on the child as long as it's a UIElement. To reference the top-left point of the child, you can use (0, 0) which is the default for Point so new Point() is enough.

        Point p = child.TranslatePoint(new Point(), viewboxInstanceParent);

good luck,

EDIT: Here's a video of this code in action: ViewboxChildPosition

omdsmr
no, it didn't work, it seams that Viewbox always treats internal content as they were not streched when dealing with TranslatePointI solved it with perspective transformation math, QuadToQuad matrix
Samir Sabri
I've added a link to a video that shows my results. Sorry if this doesn't work for you. If you have something that does, you should post it and mark is as the answer for others that might have the same problem.
omdsmr