How to get window absolute location on screen?
In WPF there was:
var location = myTextBlock.PointToScreen(new Point(0,0));
But in UWP I can't find anything similar...
Any idea on this?
How to get window absolute location on screen?
In WPF there was:
var location = myTextBlock.PointToScreen(new Point(0,0));
But in UWP I can't find anything similar...
Any idea on this?
Try this:
Assuming ctl is the control whose absolute screen coordinates you seek:
Dim ttv As GeneralTransform = ctl.TransformToVisual(Window.Current.Content)
Dim WindowCoords As Point = ttv.TransformPoint(New Point(0, 0))
Dim ScreenCoordsX as double = WindowsCoords.X + ApplicationView.GetForCurrentView().VisibleBounds.Left
Dim ScreenCoordsY as double = WindowsCoords.Y + ApplicationView.GetForCurrentView().VisibleBounds.Top
You can add ctl.ActualWidth to find the right hand side, but if you've applied a ScaleTransform to the control, you'll have to multiply ActualWidth by that same scale, as ActualWidth isn't affected by transforms.
You can't get nor set the window's location on the screen in the current UWP API. You can only partially control its size.
You can use the AdjacentToLeftDisplayEdge
and AdjacentToRightDisplayEdge
to query if the window is snapped to a side of the screen. You can also use IsFullScreenMode
property to query whether the app is full screen.