Michael Kniffen
Michael Kniffen

Reputation: 346

how to hide (not just disable) only the maximize button on a wpf window

I've been attempting to have a wpf window that only has the minimize and close buttons on the window header, and not the maximize button.

My current best attempt is the following:

private const int GWL_STYLE = -16,
                      WS_MAXIMIZEBOX = 0x10000;

internal static void HideMaximizeButton(this Window window)
{
    IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
    var currentStyle = GetWindowLong(hwnd, GWL_STYLE);
    SetWindowLong(hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX));
}

But the end result of this is just to gray out the maximize button, not to completely exclude it from the window header.

Any assistance would be greatly appreciated. Thanks

Upvotes: 2

Views: 1290

Answers (1)

jonjohnson
jonjohnson

Reputation: 423

You can't remove just the maximize button. However you can remove the whole ControlBox and add your own.

Upvotes: 3

Related Questions