Location of WPF control in window?

后端 未结 1 708
逝去的感伤
逝去的感伤 2021-02-09 18:24

Is there a way to get the current rendered location of a WPF control its window after all of the current RenderTransforms have been applied? I may just be

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 18:49

    I guess I should have kept poking before asking ... but instead of deleting maybe this will help someone later.

    The trick is to transform the point (0,0) from the control's axes to the axes of the window, so...

    Point renderedLocation = theControl.TranslatePoint(new Point(0,0), theWindow);

    If you need an interior point on the control it works similar, just use that local point instead of (0,0).

    Don't try basing it off of Margin or Padding, it doesn't come out correctly.

    0 讨论(0)
提交回复
热议问题