How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?
How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window? Any help doing this would be appreciated.
Friedrich Brunzema
Answers
- Set the Window.WindowStyle property to WindowStyle.None.
Sheva
All Replies
- Set the Window.WindowStyle property to WindowStyle.None.
Sheva Sheva,
I just tried this - it does a bit too much, removing the whole window title and border. I am trying to mimick a normal modal dialog with no icon in the title bar, and no minimize/maximize, possibly no close button.
Friedrich
I just tried setting the WindowStyle to SingleBorderWindow - this is almost what I want: I would like the possibilty of showing/hiding the Window Icon in the titlebar and the close button.
Friedrich
Seems this was overlooked in WPF. Shouldn't there be an equivilent of the MinimizeBox and MaximizeBox properties that are present in Windows Forms.
Any ideas on a workaround to disable the minimize button and leave the maximize and close button on the window?
Can someone comment on this from MSFT? What is the bext practise for disabling the Minimize / Maximize buttons when using a WPF window? I look forward to a response fro MSFT
Thanks
Disabling Minimize, Maximize buttons:
This can be achieved by setting Window.ResizeMode property to ResizeMode.NoResize. It will disable the minimize and maximize buttons. Furthermore, the window will not resize by mouse click+drag.
Not showing Icon and Close button:
Unfortunately, this feature is not available in WPF. To achieve this, you can try setting the WS_EX_DLGMODALFRAME window style by calling [Get/Set]WindowLong (pInvoking in to Win32) from the SourceInitialized event on the Window class.
- Proposed As Answer byJeffHall345 Saturday, November 22, 2008 12:35 AM
- Great! It is possible to disable the minimize and maximize using [Get/Set]WindowLong so that has resolved the issue. Thanks!
- If anyone would be kind enough to show how to use [Get/Set]WindowLong, it would be greatly appreciated!
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function<DllImport(
"user32.dll")> _ Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer End Function
Private Const GWL_STYLE As Integer = (-16) Private Sub RemoveControlBoxes() ' Dim hwnd As IntPtr = New Interop.WindowInteropHelper(Me).Handle Dim windowLong As Long = GetWindowLong(hwnd, GWL_STYLE)windowLong = windowLong
And -131073 And -65537SetWindowLong(hwnd, GWL_STYLE,
CInt(windowLong)) ' End SubThe above VB.NET code should remove the Minimize and Max. control buttons within the Window frame. Also, pinvoke.net is a handy resource for future reference.
- Hi Hamid,
I wanted to remove the Close button,but retain the Title bar..Based on the solution you gave here i tried the code and i see that the min and maximize buttons are gone. But could you please show me the code to remove the Close button while retaining the Title bar?
Thanks - Hamid says "To Disable Maximize and Minimize, set Window.ResizeMode property to ResizeMode.NoResize."
Ok, I don't want to stop all resizing.
What I want to do is allow resizing (between the min and max dimensions) but no maximising or minimising. How do I go about that? - Certainly the Minimize button should be disabled when the window is not resizable, but I should still be able to turn off the button and keep my window resizable.
Second, the minimize on a modal dialog owned by main window behaves very poorly. The dialog minimizes, focus changes to another application, say Live Messenger, but the main window of the application remains in the background and is disabled. Now if the Messenger isn't maximized, the disabled main window shows behind it and looks for all purposes like it ready to go - except its disabled.
This will trip up my users. I need to be able to turn the button off with out resorting to resize functionality on the dialog.


