Search code examples
wpfwindow-chrome

Let user grab the window to resize, outside the window


In my WPF application, I override the default window chrome by setting the WindowChrome property of the Window style (as described here).

I would like the user to be able to grab the window to resize it a few pixels outside of the window, like how Visual Studio does it. I've already played with ResizeBorderThickness, but that only seems to define the area inside the window.

How could I do this?

Below a gif demonstrating the difference between Visual Studio and my application.

Difference Visual Studio and my application


Solution

  • Visual Studio's main window is a WPF window, but it doesn't use the default window chrome provided by the OS.

    Instead, it creates a custom glow effect: actually, the effect is implemented by four native windows (each with its own HWND) which are placed around the main (WPF) window and which render themselves using bitmaps for the glow/shadow effects.

    Since these windows can handle the mouse input, they are able to switch the mouse cursor to the resize mode even before the cursor reaches the border of the main window.

    If you think that the effort of creating a custom chrome window is worth it, you could try to re-implement this functionality.

    You could also try third-party components for this, either by using them as-is or by creating your own fork based on the source code provided. E.g. take a look on a custom chrome window from the ControlzEx library.

    Otherwise, if you think that this small feature is not worth any additional effort - well, maybe it is better to just accept the default functionality.