get XY of object in wpf for this situation?

ⅰ亾dé卋堺 提交于 2019-12-24 03:01:09

问题


I have a Canvas with two or more objects. Now, I put these objects in a new Canvas placed in the previous Canvas. Then, I rotate it.

Now, I want to know how to get the positions of the objects in the new Canvas, as though there were no new canvas.


回答1:


You can use the following extension method to get the location of one UIElement with respect to another:

  public static class ExtensionMethods
  {
    public static Point GetRelativePosition(this UIElement element, UIElement other)
    {
      return element.TransformToVisual(other)
                    .Transform(new Point(0, 0));
    }
  }


来源:https://stackoverflow.com/questions/6213190/get-xy-of-object-in-wpf-for-this-situation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!