How do you disable Aero Snap in an application?

前端 未结 11 2317
一向
一向 2020-11-29 09:36

Is it possible to disable the automatic window-docking feature of Windows 7 in a WPF application?

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 10:28

    I needed to detect Windows 7 Aero snaps/docks to prevent window-size changes on a WPF application. During my search, I stumbled upon this post and found the answer given by anthony very helpful.

    Following is what worked for me.

    private void DisplayWindow_MouseMove(object sender, MouseEventArgs e) 
    {
        if (e.LeftButton == MouseButtonState.Released) 
        {
            this.ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip;
        }
    }
    
    private void DisplayWindow_LocationChanged(object sender, EventArgs e) 
    {
        this.ResizeMode = System.Windows.ResizeMode.NoResize;
    }
    

    The window's XAML had the ResizeMode="CanResizeWithGrip" setting.

    Edit:
    My response was not handle the Windows 7 Aero snap properly. bjo's response elegantly solved the problem for me.

提交回复
热议问题