在 WPF 中,类似这样的内容会告诉我边框左上角的位置:
var point = myBorder.PointToScreen(new Point());
如何在 UWP 中获得相同的结果?我找不到任何获得它的方法。
谢谢你:)
最佳答案
您可以通过以下步骤获取 UIElement 的屏幕坐标:
通过以下代码获取UIElement相对于当前应用程序窗口的坐标:
GeneralTransform transform = myBorder.TransformToVisual(Window.Current.Content); Point coordinatePointToWindow = transform.TransformPoint(new Point(0, 0));
获取当前应用窗口的
Rect
信息:Rect rect = Window.Current.CoreWindow.Bounds;
计算你的 UIElement 的坐标:
var left = coordinatePointToWindow.X + rect.Left; var top = coordinatePointToWindow.Y + rect.Top;
关于wpf - 如何在 UWP 中获取 PointToScreen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38568847/