2

How do I restrict my WPF window to only permit the maximize and minimize functions. In my application, users should not be allowed to Resize the window.

I changed my WPF window properties as per below:

Window State: Maximize

Resize Mode: NoResize

When I run my application window open in maximize view, but when I double click on the window border it Resizes. Is it possible to restrict this behavior?

psubsee2003
  • 8,563
  • 8
  • 61
  • 79
Raj
  • 351
  • 2
  • 13
  • 30

1 Answers1

1

With this piece of code Window will open in Maximized state and can be Minimized as well with No Resize. You can also specify some fixed size (Height and Width) to windows if you want like.

Height="350" Width="525" 

Xaml:

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     WindowState="Maximized" ResizeMode="CanMinimize">    
...    
</Window>

Refer to Resize Mode section in MSDN Reference: http://msdn.microsoft.com/en-us/library/ms748948.aspx

You can refer to somewhat similar post: Minimize window with NoResize mode on

Community
  • 1
  • 1
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • @FurqanSafdar A double-click in the title bar will still resize the maximized window to normal size. – Clemens Oct 06 '12 at 10:17
  • Is catching the `SizeChanged` event an option for you? You could check `WindowState` to see if it is `Maximized` or `Minimized`, and if not, set it to one of those values. Combined with this answer, it would handle the edge case that @Clemens found. – Bradley Uffner Jan 22 '18 at 13:28