Links

Current series

Visitors

Blogged

Technorati

[WPF] Hide the “Window Buttons” (minimize, restore and close) and the icon of a window

July 21, 2009 — winsharp93

No “Red-X”? Then I can’t close the window! How to achieve this reaction in WPF applications.

Even if it is not always the user friendliest way, there are situation in which you do no want the user to close a window using the “red X” in the upper right corner of a window’s non client area (sometimes only called “Close Button”😉 ).

In most cases this behavior is expected from Dialogs which usually do not have “Minimize” and “Maximize” buttons. So it’s a common practice to hide the whole so called “System Menu”, “Control Box” or “System Bar”.

Windows Forms

It’s quite easy to do so in Windows Forms: Simply set the ControlBox property to false:

publicpartialclass Form1 : Form
{
public Form1()
{
InitializeComponent();
//We want to have a dialogthis.FormBorderStyle = FormBorderStyle.FixedDialog;
//Hide the System Menu / Control Box / System Barthis.ControlBox =false;
}
}

WPF

However, a Window does not provide a property similar to WinForms’ ControlBox.

First, we set the ResizeMode to NoResize to have an effect like FixedDialog in WinForms:

>> what are your experiences with the static contract checker? i found it rather useless at this point because it misses so many cases.
I will cover the static checker in a further part of my “Code Contracts” series.
I totally agree with you: In its current state of development, the static checker is quite useless.
However, there will (hopefully) be lots of improvements and optimizations. Maybe it will be useful in the future.
And I see no disadvantages in using Code Contracts – so I use them.