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...
Good solution I put together with a little help from MSDN on detecting non-client mouse activity in WPF windows.
Calling handled = true
in the WndProc
if msg == WM_NCLBUTTONDBLCLK
will prevent the window from maximizing when the user double clicks on the non-client area.
myClass() //c'tor
{
InitializeComponent();
SourceInitialized += new EventHandler(myClass_SourceInitialized);
}
void myClass_SourceInitialized(object sender, EventArgs e)
{
System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(new System.Windows.Interop.WindowInteropHelper(this).Handle);
source.AddHook(new System.Windows.Interop.HwndSourceHook(WndProc));
}
int WM_NCLBUTTONDBLCLK { get { return 0x00A3; } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_NCLBUTTONDBLCLK)
{
handled = true; //prevent double click from maximizing the window.
}
return IntPtr.Zero;
}
Helpful MSDN ref: https://social.msdn.microsoft.com/Forums/vstudio/en-US/f54dde25-b748-4724-a7fe-a355b086cfd4/mouse-event-in-the-nonclient-window-area
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