2

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?

user3239349
  • 877
  • 1
  • 12
  • 33

2 Answers2

1

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.

zax
  • 844
  • 8
  • 14
0

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.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • 2
    You can get it. Use: ApplicationView.GetForCurrentView().VisibleBounds You just can't set it. – zax Mar 01 '18 at 23:09