Wpf – How to enforce MinWidth & MinHeight in a WPF window where WindowStyle=”None”

heightwidthwindowwpfxaml

I have a WPF application in which the main window's decoration is custom, via WindowStyle="None". I draw my own titlebar and min/max/close buttons. Unfortunately, Windows doesn't enforce my MinWidth and MinHeight properties when the window is resized, thus allowing the window to be resized all the way down to 3×3 (appx – just enough to show the handles to grow the window).

I'm already having to intercept window events (sp. 0x0024) to fix the maximization bug (where it will maximize over the windows taskbar) caused by WindowStyle=none. I'm not afraid to intercept more events to achieve what I need.

Does anyone know how to get my window to not resize below my MinWidth and MinHeight properties, if it is even possible? Thanks!!

Best Answer

I was able to solve this problem by setting handled (the last parameter for WindowProc()) to false in the case for 0x0024 (which the OP mentioned he was already hooking to fix maximization), and then setting MinHeight and MinWidth in your Window XAML. This lets the handling of this window message fall through to default WPF mechanisms.

This way, the Min* attributes on your Window manage the minimum size and the custom GetMinMaxInfo code manages the maximum size.