Disable maximizing WPF window on double click on the caption

Alex Klaus picture Alex Klaus · Apr 18, 2013 · Viewed 9.2k times · Source

How to disable maximizing WPF window on double click on the caption and leave resizing available?


I know that ResizeMode disables maximizing, but it also prevents resizing the form

ResizeMode="CanMinimize"

I know how to remove maximize and minimize buttons, but it's still possible to maximize by double click on the caption.

In WinForms it can be achieved easily. Just set FormBorderStyle from None to FixedSingle or Fixed3D. But it's not an option in WPF any more.


P.S. I'm trying some tricks with handling WM_GETMINMAXINFO, WM_SYSCOMMAND, etc. But seems it's not working...

Answer

Marek Dzikiewicz picture Marek Dzikiewicz · Mar 8, 2014

I had a similar issue. My window does not have any form border or title bar, but it can be moved around (using the mouse). The problem is that if a user moves the window to the top edge of the screen, then Windows automatically maximizes the window.

I managed to work around this issue by attaching the following handler to the window's StateChanged event.

private void OnWindowStateChanged(object sender, EventArgs e)
{
    if (this.WindowState == WindowState.Maximized)
    {
        this.WindowState = WindowState.Normal;
    }
}