disable maximize capacity in a wpf window
Asked Answered
S

3

5

I'm trying to disable the maximize capacity (not the maximize button) in a wpf window, but so far nothing has succeded.

I'm using a window with WindowStyle="none", but when I drag the window to the far top of the screen, the OS "maximizes" the window (terribly bad, by the way).

I uploaded 3 pictures to show what is happening exactly.

(however, due to the fact that I don't have 10 reputation, I have to post the links instead. Sorry about that. And I can't put all 3 links, only 2 of them, but the first one is just of the window working normally)

During: https://static.mcmap.net/file/mcmap/ZG-Ab5ovKRk0NC2AZV22bFljKmMva3/243lr89.jpg

After: https://static.mcmap.net/file/mcmap/ZG-Ab5ovKRkRLi2AZV22bFljKmMva3/f3c1mu.jpg

Salmagundi answered 4/6, 2015 at 16:36 Comment(3)
Try to set maxwidth and maxheight property then try again. Let me know if this works.Ciaracibber
Hi Abin. I set it to 2000 just to give it a try, but it didn't work.Salmagundi
try this MaxHeight="350" MaxWidth="525"Ciaracibber
A
6

use the window state change event:

private void Window_StateChanged(object sender, EventArgs e)
{
    if (this.WindowState == System.Windows.WindowState.Maximized) 
    {
        this.WindowState = System.Windows.WindowState.Normal; 
    }
}
Aliquant answered 15/9, 2016 at 0:52 Comment(3)
Works, but it's a horribly ugly thing to watch as it jumps out and back. That event is way too late to be useful in production.Disregardful
Unfortunately that's the only solution I know and use. I will be curious to know alternate solutions, if you could find and share here.Aliquant
The best solution thus far has been the p/invoke on message preview.Disregardful
C
1

Set MaxHeight,MinHeight and MaxWidth,MinWidth property for the window.

Example

 <Window x:Class="test.MainWindow"        
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                
    Title="MainWindow" MaxHeight="350" MaxWidth="525" MinHeight="350" MinWidth="525">
</Window>

How do you disable Aero Snap in an application?

Ciaracibber answered 4/6, 2015 at 17:0 Comment(8)
Hi. I just did that, with 525 in both fields. It still let me maximize the window when I move it to the top of the window. (However, now the area covered from the maximized window is not all of the screen but just 525x525 in the top left corner.Salmagundi
Nop, it still let me maximize the window, but now the "maximized" window has an area of "maxwidth" by "maxheight".Salmagundi
@JulianDavidBautistaOsorio Did u tried this way ? MaxHeight="350" MaxWidth="525" MinHeight="350" MinWidth="525"Ciaracibber
Yes, my window has values for those minheight and minwidth fields as well. This is what happens: I drag the window to the top: The borders of my working window are set to the min values, and the dark area ocupied (but useless) by the maximized window are set to the max values. It wont let me drag it after maximizing the window.Salmagundi
And by the way, I can't just set small values for my window, since its resizable and the user can expand it or contract it.Salmagundi
#19475758Ciaracibber
#2471185Ciaracibber
The first link didn't help me. But the guy in the second link was having the same problem I did, and his solution, even though it's not "pretty", it works well. THANK YOU FOR YOUR HELP!!! :)Salmagundi
P
0

I know that this is quite old, but I found a better solution than the proposed one: Instead of catching a maximize event, you can just override the WndProc method:

protected override void WndProc(ref Message m) {
    if(m.Msg == 0x0112 && m.WParam == new IntPtr(0xF032)
        return;
    base.WndProc(ref m);
}
Pythoness answered 18/1 at 6:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.