Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable maximize button of WPF window, keeping resizing feature intact

Tags:

c#

.net

wpf

So WPF windows only have four resize mode options: NoResize, CanMinimize, CanResize and CanResizeWithGrip. Unfortunately, the options that enable resizing also enable maximizing the window, and those that don't are useless to me.

Is there an option to disable the maximize button while keeping the resize feature?

I'd prefer solutions that don't involve WinAPI stuff.

like image 218
Peter W. Avatar asked Sep 09 '13 22:09

Peter W.


People also ask

How to disable maximize button in WPF?

Use the ResizeMode property By setting the ResizeMode property to CanMinimize only the Minimize button will be visible. The maximize button will be hidden and the resizing will be disabled.

How do I disable maximize button?

Minimize button enables users to minimize the window to the taskbar. To remove minimize button we have to set the MinimizeBox property to false of the windows form. Now when you open the windows form you will notice the windows form's minimize button is in disable mode in the windows form.

Can you resize with grip?

The CanResizeWithGrip option is similar to CanResize, but the lower right corner of the window shows a little “grip” icon indicating that you can “grab” the window here to resize it. The NoResize option creates a window that can't be resized, minimized or maximized.

Which button is used to maximize the size of window?

To maximize a window, grab the titlebar and drag it to the top of the screen, or just double-click the titlebar. To maximize a window using the keyboard, hold down the Super key and press ↑ , or press Alt + F10 .


3 Answers

Disabled only Maximize:

ResizeMode="CanMinimize"
like image 81
5573352 Avatar answered Oct 06 '22 21:10

5573352


WPF does not have the native capability to disable the Maximize button alone, as you can do with WinForms. You will need to resort to a WinAPI call. It's not scary:

[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

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

private void Window_SourceInitialized(object sender, EventArgs e)
{
    var hwnd = new WindowInteropHelper((Window)sender).Handle;
    var value = GetWindowLong(hwnd, GWL_STYLE);
    SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MAXIMIZEBOX));
}
like image 22
Scott Avatar answered Oct 06 '22 21:10

Scott


If you set

WindowStyle="ToolWindow"

In your window's properties, it will give you a resizable window with no minimize or maximize buttons at the top. It'll be square looking and the close button is also square, but at least minimize and maximize aren't there!

like image 33
TranquilMarmot Avatar answered Oct 06 '22 22:10

TranquilMarmot