0

I have a WPF application that has a Window that is with a WindowStyle of none, and is resizable. I didn't want the user to be able to minimize or maximize the Window so I just didn't expose buttons for those operations. This works well, but I just realized on Win7+ you can maximize a Windows simply by dragging it near the top of the screen.

Is there some way to suppress or override this behavior? Thanks.

kmarks2
  • 4,755
  • 10
  • 48
  • 77
  • possible duplicate of [How to? WPF Window - Maximized, No Resize/Move](http://stackoverflow.com/questions/3318385/how-to-wpf-window-maximized-no-resize-move) – Paul C Feb 12 '14 at 15:37
  • It's kind of the inverse of that question though. I am not a dedicated WPF developer so what I tried was just not exposing the minimize/maximize buttons, which worked fine until the product started getting used on Windows 7. I looked for a Maximize event to handle, but there is none. – kmarks2 Feb 12 '14 at 15:43

2 Answers2

0

Please try the following:

ResizeMode="NoResize" WindowStyle="ToolWindow"

WindowStyle="ToolWindow" removes the Min/Max icons on the top right window corner. ResizeMode="NoResize" prevents the window from being resizable.

Wagner DosAnjos
  • 6,304
  • 1
  • 15
  • 29
  • I have `WindowStyle="None"` right now as a requirement because we have custom window UI conventions -- in said convention I just didn't include min/max buttons. It also needs to be resizable. – kmarks2 Feb 12 '14 at 15:52
  • Humm... probably in that case you can fix the MinWidhth/MaxWidth and MinHeight/MaxHeight to force a particular size. – Wagner DosAnjos Feb 12 '14 at 15:59
0

Pieced this together from a few other questions:

private void image_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
   if (e.LeftButton == MouseButtonState.Pressed)
   {
      //This prevents win7 aerosnap
      if (this.ResizeMode != System.Windows.ResizeMode.NoResize)
      {
         this.ResizeMode = System.Windows.ResizeMode.NoResize;
         this.UpdateLayout();
         DragMove();
         this.ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip;
      }
      else
         DragMove();
   }
}
kmarks2
  • 4,755
  • 10
  • 48
  • 77