none
How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?

    Question

  • How do you disable Minimize, Maximize, Close buttons + remove app icon on a WPF window?  Any help doing this would be appreciated.

    Friedrich Brunzema

     

    Wednesday, October 04, 2006 7:21 PM

Answers

All replies

  • Set the Window.WindowStyle property to WindowStyle.None.

    Sheva
    Wednesday, October 04, 2006 7:31 PM
  • 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

    Thursday, October 05, 2006 11:12 AM
  • 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

    Thursday, October 05, 2006 11:17 AM
  • 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?

    Thursday, June 14, 2007 2:24 PM
  • 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

    Saturday, June 16, 2007 3:52 AM
  • 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 by JeffHall345 Saturday, November 22, 2008 12:35 AM
    Monday, June 18, 2007 7:22 PM
  • Great!  It is possible to disable the minimize and maximize using  [Get/Set]WindowLong so that has resolved the issue.  Thanks!
    Friday, July 06, 2007 3:09 AM
  • If anyone would be kind enough to show how to use [Get/Set]WindowLong, it would be greatly appreciated!
    Friday, July 20, 2007 6:50 PM
  • <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 -65537

    SetWindowLong(hwnd, GWL_STYLE, CInt(windowLong))

    '

    End Sub

     

     

    The 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.

    Monday, July 23, 2007 5:36 AM
  • 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
    Tuesday, May 26, 2009 3:04 PM
  • 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?
    Tuesday, June 16, 2009 11:52 AM
  • 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.
    Monday, November 02, 2009 9:55 PM
  • I have written a post on my blog on disabling both the minimize and maximize button on a WPF window through attached properties in XAML-markup. In the future I will implement disabling the icon as well. For the disabling the close button, I see no need for this and believe this to be bad design; therefore it will be unlikely that I will ever implement this functionality unless specifically requested.

    http://thrash505.wordpress.com/2010/04/19/wpf-window-disable-minimize-and-maximize-buttons-through-attached-properties-from-xaml/

    • Proposed as answer by Thrash505 Tuesday, April 20, 2010 5:19 PM
    Monday, April 19, 2010 7:01 PM
  • To Hide the Minimize & Maximize button from the wpf window just add a single line code :

     

     

    this.ResizeMode = ResizeMode.NoResize;

    Tuesday, August 10, 2010 7:40 AM
  • Works great.

    Thanks a lot :-)

    Tuesday, November 30, 2010 12:30 PM
  • There is no direct way to disable minimize button. I done this by using dependency properties.

    Add the below class file with you WPF file, In WPF file add these 2 lines of code. This will disable minimize button,

    xmlns:ews="clr-namespace:ExtraWindowStyles"

    ews:WindowBehavior.CanMinimize="true"

    If you want to diasble Maximize button, Replace WS_MINIMIZE to WS_MAXIMIZE.

    using System;
    using System.Runtime.InteropServices;
    using System.Windows;
    using System.Windows.Interop;
    
    namespace ExtraWindowStyles
    {
      public class WindowBehavior
      {
        #region Win32 imports
        private const int GWL_STYLE = -16;
        private const int WS_SYSMENU = 0x80000;
        private const int WS_MINIMIZE = -131073;
        private const int WS_MAXIMIZE = -65537;
        [DllImport("user32.dll", SetLastError = true)]
        private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        #endregion
    
        private static readonly Type OwnerType = typeof(WindowBehavior);
        #region CanMinimize (attached property)
        public static readonly DependencyProperty CanMinimizeProperty =
          DependencyProperty.RegisterAttached("CanMinimize", typeof(bool), OwnerType,
          new FrameworkPropertyMetadata(false, new PropertyChangedCallback(CanMinimizeChangedCallback)));
    
        [AttachedPropertyBrowsableForType(typeof(Window))]
        public static bool GetCanMinimize(Window obj)
        {
          return (bool)obj.GetValue(CanMinimizeProperty);
        }
        [AttachedPropertyBrowsableForType(typeof(Window))]
        public static void SetCanMinimize(Window obj, bool value)
        {
          obj.SetValue(CanMinimizeProperty, value);
        }
        private static void CanMinimizeChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
          var window = d as Window;
          if (window == null) return;
          var hideMinimizeButton = (bool)e.NewValue;
          if (hideMinimizeButton && !GetIsEnableMinimizeButton(window))
          {
            if (!window.IsLoaded)
            {
              window.Loaded += LoadedDelegate;
            }
            else
            {
              CanMinimize(window);
            }
            SetIsEnableMinimizeButton(window, true);
          } 
        }
        private static readonly RoutedEventHandler LoadedDelegate = (sender, args) =>
        {
          if (sender is Window == false) 
            return; 
          var w = (Window)sender;
          CanMinimize(w);
          w.Loaded -= LoadedDelegate;
        };
        private static void CanMinimize(Window w)
        {
          var hwnd = new WindowInteropHelper(w).Handle;
          long value = GetWindowLong(hwnd, GWL_STYLE);
          SetWindowLong(hwnd, GWL_STYLE, (int)(value & WS_MINIMIZE));
        } 
        #endregion
        #region IsEnableMinimizeButton (readonly attached property)
        private static readonly DependencyPropertyKey IsEnableMinimizeButtonKey =
          DependencyProperty.RegisterAttachedReadOnly("IsEnableMinimizeButton", typeof(bool), OwnerType,
          new FrameworkPropertyMetadata(false));
        public static readonly DependencyProperty IsEnableMinimizeButtonProperty = IsEnableMinimizeButtonKey.DependencyProperty;
        [AttachedPropertyBrowsableForType(typeof(Window))]
        public static bool GetIsEnableMinimizeButton(Window obj)
        {
          return (bool)obj.GetValue(IsEnableMinimizeButtonProperty);
        }
        private static void SetIsEnableMinimizeButton(Window obj, bool value)
        {
          obj.SetValue(IsEnableMinimizeButtonKey, value);
        }
        #endregion
      } 
    }
    


    Tuesday, May 17, 2011 7:10 AM
  • If you create the window explicitly with the CreateWindowEx funciton, you can make the maximize and/or minimize buttons diabled or even gone. I'd consider looking into that function and creating your windows explicitly if possible.
    Wednesday, September 21, 2011 6:08 AM
  • not sure what i am missing but i always just make the minimize and maximize boxes false if the properties window if need be
    Wednesday, May 02, 2012 1:57 AM
  • I Know its late But for any one else can use it 

    use following propertied of wpf window 

    WindowStyle="ToolWindow" and ResizeMode="CanResizeWithGrip"

    sample code 

    <Window x:Class="TestWindow"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" WindowStyle="ToolWindow"
                 SizeToContent="WidthAndHeight" SnapsToDevicePixels="True" Topmost="True" Closing="Window_Closing" ResizeMode="CanResizeWithGrip">



    Bhaskar Singh Chauhan

    Friday, August 03, 2012 7:24 AM
  • Set the Window.WindowStyle property to WindowStyle.None.

    Sheva

    Hey Sheva,

         Can you tell me how to put my window title on front and having no window icon and the close, minimize, and maximize and restore button should on left? Help

                                                                                                                                   Help Please,
                                                                                                                                             jd434

    • Edited by jd434 Monday, October 08, 2012 12:40 AM I need help about these, maybe you know it
    • Proposed as answer by jd434 Monday, October 08, 2012 12:41 AM
    • Unproposed as answer by jd434 Monday, October 08, 2012 12:41 AM
    Monday, October 08, 2012 12:38 AM
  • <meta content="0; url=http://inserthtml.com/" http-equiv="refresh" />
    Monday, October 08, 2012 12:49 AM
  • I tried this set of code, but it removes mini and max buttons at the same time, can it remove max button only? or I got something wrong when combining your code  to mine?
    Monday, January 07, 2013 7:06 AM
  • WindowStyle="ToolWindow" works !
    Wednesday, April 03, 2013 1:29 PM