Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get PointToScreen in UWP

Tags:

wpf

xaml

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 :)

like image 692
adminSoftDK Avatar asked Sep 11 '25 20:09

adminSoftDK


2 Answers

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;
    
like image 67
Elvis Xia - MSFT Avatar answered Sep 15 '25 16:09

Elvis Xia - MSFT


You can use TransformToVisual method. Use the following code

var transformToVisual = myBorder.TransformToVisual(Window.Current.Content);
var borderCoordinats = transformToVisual .TransformPoint(new Point(0, 0));
like image 39
Andrii Krupka Avatar answered Sep 15 '25 15:09

Andrii Krupka