Disabling Minimize and Maximize buttons in a WPF Window

In WPF there is no possibility to control when the Minimize and Maximize buttons are disabled when the WindowStyle is SingleBorderWindow or ThreeDBorderWindow. In Windows Forms there are some properties like ControlBox, MinimizeBox and MaximizeBox that allow to do that.

Because the WPF window internally has a hWnd we can do this using Windows API (GetWindowLong and SetWindowLong will do the trick). I did three attached properties applicable to Window that use the internal API, in order to disable/hide the minimize and maximize buttons. You can use the two following attached properties:

<Window

   l:ControlBox.HasMinimizeButton="false"

   l:ControlBox.HasMaximizeButton="false">

The third attached property is to enable the context help button. This button is added only if the minimize and maximize buttons are not present, then the right configuration to use the context help button is:

<Window

   l:ControlBox.HasMinimizeButton="false"

   l:ControlBox.HasMaximizeButton="false"

   l:ControlBox.HasHelpButton="true">

You can download the code here.

No Comments