Handle the WM_GETMINMAXINFO message for your window, and do whatever re-sizing you need to do
public MainWindow()
{
InitializeComponent();
SourceInitialized += new EventHandler(win_SourceInitialized);
}
private void win_SourceInitialized(object sender, EventArgs e)
{
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
}
private const int WM_GETMINMAXINFO = 0x0024;
private static System.IntPtr WindowProc(
System.IntPtr hwnd,
int msg,
System.IntPtr wParam,
System.IntPtr lParam,
ref bool handled)
{
switch (msg)
{
case WM_GETMINMAXINFO: //https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-getminmaxinfo
WmGetMinMaxInfo(hwnd, lParam); // <------ Do what you need to here ---------->
handled = true;
break;
}
return (System.IntPtr)0;
}
Note that if you are a borderless, not-resizable window, you may also need to get the monitor info (via the Win32 GetMonitorInfo) and restrict your application to the work area of the monitor it is on. On our systems, windows does not correctly size the window for 1900x1200 monitors (it makes it too tall, so we have to set the MaxHeight based on the Monitor Info, and pay attention for that to change if the taskbar is resized by continuing to watch the WM_GETMINMAXINFO messages).
This blog can probably help with that if you have those issues as well:
https://blogs.msdn.microsoft.com/llobo/2006/08/01/maximizing-window-with-windowstylenone-considering-taskbar/