wpf - 如何在 UWP 中获取 PointToScreen

标签 wpf xaml uwp

在 WPF 中,类似这样的内容会告诉我边框左上角的位置:

        var point = myBorder.PointToScreen(new Point());

如何在 UWP 中获得相同的结果?我找不到任何获得它的方法。

谢谢你:)

最佳答案

您可以通过以下步骤获取 UIElement 的屏幕坐标:

  1. 通过以下代码获取UIElement相对于当前应用程序窗口的坐标:

    GeneralTransform transform = myBorder.TransformToVisual(Window.Current.Content);
    Point coordinatePointToWindow = transform.TransformPoint(new Point(0, 0));
    
  2. 获取当前应用窗口的Rect信息:

    Rect rect = Window.Current.CoreWindow.Bounds;
    
  3. 计算你的 UIElement 的坐标:

    var left = coordinatePointToWindow.X + rect.Left;
    var top = coordinatePointToWindow.Y + rect.Top;
    

关于wpf - 如何在 UWP 中获取 PointToScreen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38568847/

相关文章:

xaml - 在DatePicker更改时刷新表格

uwp - Windows 10 分配的访问权限 : how to logout programmatically

c# - Windows UWP BluetoothLE设备缓存

c# - EventToCommand 和 CommandManagerBinding 不工作

c# - 播放视频时图片闪烁的页面

c# - Catel 框架 - 替换 View

c# - 从手机方向更改中锁定特定的 UI 项目?

c# - 使用自定义商店区域解析货币

wpf - 链接内容不适用于资源词典

c# - 我怎样才能移动粘性/捕捉 wpf 窗口