Test project in (.NET framework 4.8) WPF, including window with full windows snap support on custom caption buttons
If you don't want to manage all this features/issues by yourself, I recommend using ControlzEx or any other library. I've created this project as test for implementing these features to our legacy application, where I cannot simply change base classes and use any other library.
NOTE: While the Debugger is attached, the resize can be a bit flickery. When the debugger is detached everything is smooth
This project features code that enables this features, when using WindowStyle.None
:
- using Windows Snap feature (automatically snap window to all sides of screen or maximizing/restoring the window)
- this is done using the
WindowChrome
feature (available from .NET Framework 4.5) - also, when using the
WindowChrome
object, you don't need to useDragMove()
and handle resizing by yourself anymore - it's all there
- this is done using the
- using Windows Snap preview feature (Windows 11+)
- this is done by identifying Maximize button in
NCHITTEST (0x0084)
message asHTMAXBUTTON
- see file
MainWindow.MaximizeSnap.cs
- this code also includes fix for maximize button effects not being triggered (hover and press) by explicitly setting internal dependency properties
- this is done by identifying Maximize button in
- the Maximize feature of
WindowsStyle.None
requires fixing window size and position- this is done by using the code in
MainWindow.Fullscreen.cs
- also, there is need to refresh
WindowChrome
and setResizeBorderThickness
to zero (disable resizing), as it partially breaks the ability to put the window back "down"
- this is done by using the code in
The code in this repo is mix of various sources:
- https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.windowchrome?view=netframework-4.8
- https://stackoverflow.com/questions/19280016/windowchrome-resizeborderthickness-issue
- https://stackoverflow.com/questions/69797178/support-windows-11-snap-layout-in-wpf-app
- dotnet/wpf#4825
- https://gitlab.com/jplibraries/windowsextensionlibrary/
- https://stackoverflow.com/questions/70976583/get-real-screen-resolution-using-win32-api - DPI per monitor handling
- and possibly some other places I've already forgot