开发者

get XY of object in wpf for this situation?

开发者 https://www.devze.com 2023-03-09 19:28 出处:网络
I have a Canvas with two or more objects. Now, I put these objects in a new Canvas placed in the pre开发者_C百科vious Canvas. Then, I rotate it.

I have a Canvas with two or more objects. Now, I put these objects in a new Canvas placed in the pre开发者_C百科vious 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.

get XY of object in wpf for this situation?


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));
    }
  }
0

精彩评论

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

关注公众号