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: http://i58.tinypic.com/243lr89.jpg

After: http://i62.tinypic.com/f3c1mu.jpg

Glorfindel
  • 21,988
  • 13
  • 81
  • 109

2 Answers2

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; 
    }
}
Anant Anand Gupta
  • 650
  • 1
  • 11
  • 22
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?

Community
  • 1
  • 1
Abin
  • 2,868
  • 1
  • 23
  • 59
  • 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. – Julian David Bautista Osorio Jun 04 '15 at 17:14
  • Nop, it still let me maximize the window, but now the "maximized" window has an area of "maxwidth" by "maxheight". – Julian David Bautista Osorio Jun 04 '15 at 17:30
  • @JulianDavidBautistaOsorio Did u tried this way ? MaxHeight="350" MaxWidth="525" MinHeight="350" MinWidth="525" – Abin Jun 04 '15 at 17:31
  • 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. – Julian David Bautista Osorio Jun 04 '15 at 17:38
  • 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. – Julian David Bautista Osorio Jun 04 '15 at 17:41
  • http://stackoverflow.com/questions/19475258/how-to-disable-maximizing-of-a-window-when-the-window-is-moved-to-the-top-left-c – Abin Jun 04 '15 at 17:44
  • 1
    http://stackoverflow.com/questions/2470685/how-do-you-disable-aero-snap-in-an-application – Abin Jun 04 '15 at 17:49
  • 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!!! :) – Julian David Bautista Osorio Jun 04 '15 at 18:42