【问题标题】:How do I get PointToScreen in UWP如何在 UWP 中获取 PointToScreen
【发布时间】:2016-11-28 20:38:48
【问题描述】:

在 WPF 中,这样的事情会告诉我边框左上角的位置:

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

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

谢谢你:)

【问题讨论】:

标签: wpf xaml uwp


【解决方案1】:

您可以通过以下步骤获取 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;
    

【讨论】:

  • 我接受了另一个答案,但你给了我更多信息。谢谢你:)
【解决方案2】:

您可以使用TransformToVisual 方法。使用以下代码

var transformToVisual = myBorder.TransformToVisual(Window.Current.Content);
var borderCoordinats = transformToVisual .TransformPoint(new Point(0, 0));

【讨论】:

    猜你喜欢
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    相关资源
    最近更新 更多