开发者

WPF: Viewbox and TranslatePoint

开发者 https://www.devze.com 2022-12-23 17:20 出处:网络
I have a Viewbox with a Canvas Child, I have the Stretch property of Viewbox to Fill, I have changed the width and height o开发者_Python百科f the Viewbox,
  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 o开发者_Python百科f 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消