Reputation: 2092
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
Reputation: 10841
You can get the screen coordinates of UIElement in following steps:
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));
Get the Rect
information of current application window:
Rect rect = Window.Current.CoreWindow.Bounds;
Calculate the coordinates of your UIElement:
var left = coordinatePointToWindow.X + rect.Left;
var top = coordinatePointToWindow.Y + rect.Top;
Upvotes: 7
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