Click here to Skip to main content
15,947,785 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Is there any way to disable the maximize button in WPF page or to disable the resize property of page using XAML or C#


When I searched in Google , I got to disable it in WPF window

How can it possible in WPF page.

Pls suggest me the sample code snippet.
Posted
Updated 9-Apr-22 23:39pm

In your MainWindow just set ResizeMode="NoResize"
 
Share this answer
 
In first (Window) tag on MainWindow.xaml page add
C#
ResizeMode="CanMinimize"
 
Share this answer
 
Comments
CHill60 6-Sep-13 8:46am    
Two years after the question was posted I'm afraid your answer doesn't add much that wasn't already in solutions 1 and 5
ataraxia89 11-Jul-19 8:02am    
@CHill60 none of the other solutions explain how to remove the maximize button only
 
Share this answer
 
You can disable windows border and inside your window add close button only :) It's not that hard to do
 
Share this answer
 
There is no direct way to disbale the X button (in property ) in a Windows Form, like there is a property for Maximize button called MaximizeBox = false Or Minimize Box = false.

Notes: Before you use code, Please add a Close button in your form so that you can close your app.

Add the following library
using System.Runtime.InteropServices;
Declare the following as class level variable
const int MF_BYPOSITION = 0x400;
[DllImport("User32")]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("User32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32")]
private static extern int GetMenuItemCount(IntPtr hWnd);

In the Form_Load() event, write the following code
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hMenu = GetSystemMenu(this.Handle, false);
int menuItemCount = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
}
 
Share this answer
 
I too was facing this same problem. The solution that i got is:

private void Page_Loaded(object sender, RoutedEventArgs e)
{
((NavigationWindow)LogicalTreeHelper.GetParent(this)).ResizeMode = ResizeMode.NoResize;
}


If you are using the NavigationWindow(a WPF page is default displayed in a NavigationWindow), we can set the ResizeMode of the NavigationWindow. :)
 
Share this answer
 
Try this :
ResizeMode="NoResize" , WindowStyle="ToolWindow"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900