0

I have a borderless window (with dragging enabled) in a WPF Application on .NET Core 3.1.

How can I conditionally enable, disable, or modify Windows 10 resizing/movement through Windows Key + Arrow, or by dragging to the edge of the screen (without modifying the registry to get rid of this behavior altogether)?

VirtualValentin
  • 1,131
  • 1
  • 11
  • 19
  • 1
    Does this answer your question? [WPF Borderless Window issues: Aero Snap & Maximizing](https://stackoverflow.com/questions/13422666/wpf-borderless-window-issues-aero-snap-maximizing) – Ankur Tripathi Dec 12 '19 at 09:23
  • @AnkurTripathi That's a great resource. Thanks! I can't really use Windows Chrome because my application is an irregular shape with custom minimize/close to tray behaviors. In particular, I was dealing with issues #5 and #6 there, but the solution still isn't perfect in multi-monitor situations with different resolutions. I'm also looking at overriding this behavior depending on the state of my window (docked/undocked, etc). The answer I put below works for me, but I'll try that solution and test it on different monitor configurations. – VirtualValentin Dec 12 '19 at 09:42

1 Answers1

0

In case someone else runs into the same problem, these were the solutions I found:

For overriding the Windows 10 snapping/resizing to the edge of the screen when dragging, I changed the resize mode to NoResize and then changed back to my preferred resize mode after the drag was complete.

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
     if (e.ChangedButton == MouseButton.Left)
     {
          this.ResizeMode = ResizeMode.NoResize;
          this.DragMove();
          this.ResizeMode = ResizeMode.CanResizeWithGrip;
     }
}

For overriding the Windows Key + Arrow combination, I did a similar thing by catching the Windows Key press in Preview Key Up/Down:

private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
     if (e.Key == Key.LWin || e.Key == Key.RWin)
     {
          this.ResizeMode = ResizeMode.NoResize;
     }
}

private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
{
     if (e.Key == Key.LWin || e.Key == Key.RWin)
     {
          this.ResizeMode = ResizeMode.CanResizeWithGrip;
     }
}

I suppose you could also catch the arrow key press after the Window Key if you wanted to modify this key combination to do something else (such as moving to a different window, but not resizing).

If anyone has a better solution, I'm all ears, but this seemed to work for me and seemed pretty simple.

VirtualValentin
  • 1,131
  • 1
  • 11
  • 19