adminSoftDK
adminSoftDK

Reputation: 2092

How do I get PointToScreen in UWP

In WPF something like this would tell me where the border top left corner:

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

How do I get the same in UWP? I can't find any way to get it.

Thank you :)

Upvotes: 4

Views: 1337

Answers (2)

Elvis Xia - MSFT
Elvis Xia - MSFT

Reputation: 10841

You can get the screen coordinates of UIElement in following steps:

  1. Get the coordinates of UIElement relative to current application window by following codes:

    GeneralTransform transform = myBorder.TransformToVisual(Window.Current.Content);
    Point coordinatePointToWindow = transform.TransformPoint(new Point(0, 0));
    
  2. Get the Rect information of current application window:

    Rect rect = Window.Current.CoreWindow.Bounds;
    
  3. Calculate the coordinates of your UIElement:

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

Upvotes: 7

Andrii Krupka
Andrii Krupka

Reputation: 4306

You can use TransformToVisual method. Use the following code

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

Upvotes: 3

Related Questions