2

I am using AppWindow (https://learn.microsoft.com/en-us/uwp/api/windows.ui.windowmanagement.appwindow) to create a second window for my UWP app. I need to detect when the user changes the location of this secondary window (i.e. she drags the window over the screen). Currently, I am listening to the following events:

  • AppWindow.Changed
  • UIElement.XamlRoot.Changed

which detect when the user resizes the window, but not when the window is simply moved (keeping exactly the same Width & Height).

Is there another event which I can listen to?

BTW, the same applies also for the old good Windows.UI.Xaml.Window: is there an event I can listen to for its movement (not resizing)?

Cristiano Ghersi
  • 1,944
  • 1
  • 20
  • 46

1 Answers1

0

I just today had a similar situation. I need to know the resolution of the monitor that the UWP app is currently displayed on, even when moved. As noted, you can capture the resize event, but there is no move event.

I solved my specific problem by adding a timer to my page:

Private WithEvents mTimer As DispatcherTimer
mTimer = New DispatcherTimer With {.Interval = New TimeSpan(0, 0, 0, 1)}
mTimer.Start()

Then capturing the TickEvent and checking the screen coordinates to see if they have changed for my page using:

Dim ScreenCoordsX As Double = ApplicationView.GetForCurrentView().VisibleBounds.Left
Dim ScreenCoordsY As Double = ApplicationView.GetForCurrentView().VisibleBounds.Top

Which I found here (c# UWP window location on screen issue).

The coordinates returned here are logical for all monitors seen as one big area, so any change means a screen move.

Might not work for everyone but is solved my specific issue.

Calphalon
  • 68
  • 10