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.
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.
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.
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.
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 .
Disabled only Maximize:
ResizeMode="CanMinimize"
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));
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With