我正在寻找一种方法来转换与屏幕上的视觉点相关的给定点。我找到了这个解决方案:
我无法理解 thepointRoot
和 the之间的不同,pointClient
因为它们似乎一直都是平等的:
// [...]
// Translate the point from the visual to the root.
GeneralTransform transformToRoot = relativeTo.TransformToAncestor(root);
Point pointRoot = transformToRoot.Transform(point);
// Transform the point from the root to client coordinates.
Matrix m = Matrix.Identity;
Transform transform = VisualTreeHelper.GetTransform(root);
if (transform != null)
m = Matrix.Multiply(m, transform.Value);
Vector offset = VisualTreeHelper.GetOffset(root);
m.Translate(offset.X, offset.Y);
Point pointClient = m.Transform(pointRoot);
// [...]
(完整代码请点击链接)
似乎VisualTreeHelper.GetOffset(root)
试图获得窗口的变换......