disable maximize capacity in a wpf window

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

Upvotes: 5

Views: 4615

Answers (3)

WereElf
WereElf

Reputation: 35

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);
}

Upvotes: 0

Anant Anand Gupta
Anant Anand Gupta

Reputation: 738

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; 
    }
}

Upvotes: 6

Abin
Abin

Reputation: 2956

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?

Upvotes: 1

Related Questions