【问题标题】:WPF - Translate a point relative to MainWindow to it's coordinates relative to a child controlWPF - 将相对于 MainWindow 的点转换为相对于子控件的坐标
【发布时间】:2011-02-05 09:11:27
【问题描述】:

是否可以将相对于 MainWindow 的点转换为相对于其子控件之一?例如,假设控件的左上角相对于 MainWindow 位于 500, 500,什么代码会将该数字转换为 (0, 0)?我希望解决方案与布局机制无关(即不需要我在 Canvas 中设置控件的父级并使用 Top 和 Bottom 方法)。

【问题讨论】:

    标签: wpf layout wpf-controls transform


    【解决方案1】:

    UIElement.TranslatePoint。例如:

    var translatedPoint = mainWindow.TranslatePoint(new Point(500, 500), childControl)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多