在这种情况下获取对象在wpf的XY? [英] get XY of object in wpf for this situation?

查看:222
本文介绍了在这种情况下获取对象在wpf的XY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Canvas ,有两个或多个对象。
现在,我把这些对象放在上一个 Canvas 中的一个新的 Canvas 中。然后,我旋转它。

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.

现在,我想知道如何获取对象的位置在新的 Canvas

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

推荐答案

您可以使用以下扩展方法获取 UIElement 相对于另一个:

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

这篇关于在这种情况下获取对象在wpf的XY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆