9

I've just switched over from WinForms to wpf and in WinForms removing the whole title box is very simple, just set the title="" and ControlBox=false.

Now there's many suggestions on how to do this with wpf, all of them using native Win32 calls. Although they do remove the control box, they still leave a thicker border at the top.

I'm certain it's doable using some kind of native call, but how?

Community
  • 1
  • 1
moevi
  • 105
  • 1
  • 1
  • 3

3 Answers3

11

Well, try this

WindowStyle="none"

like this:

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"  WindowStyle="None"
    MinHeight="350" MaxHeight="350" MinWidth="525" MaxWidth="525">
<Grid>

</Grid>
</Window>

Edit:

It looks a little stupid but this way (with Min- and MaxHeight/Width at the same size) you can prevent the window from beeing resized

Tokk
  • 4,499
  • 2
  • 31
  • 47
  • Oh, I feel kinda stupid now. Anyway, I realize now that I have tried that solution before, but the reason it didn't work was because I had also set ResizeMode=NoResize, this completely removes the border. So I guess the real question is: How do I get the WindowStyle=None look and at the same time prevent the window from being resized? – moevi Nov 04 '10 at 21:48
6

This is an alternative way of doing it. To remove the Max-/minimize you need to change the ResizeMode like this

<Window x:Class="MyWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="" Height="350" Width="525" ResizeMode="NoResize">
    <Grid>

    </Grid>
</Window>

After that you can remove the Close button by adding this ( read more here )

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[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);

public MainWindow()
{
    SourceInitialized += Window_SourceInitialized;
}

void Window_SourceInitialized(object sender, EventArgs e)
{
    var hwnd = new WindowInteropHelper(this).Handle;
    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
Community
  • 1
  • 1
Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • but us will let you have the title bar, too. WindowsStyle="none" does exatly what is shown in the Picture and is much more simple ;-) – Tokk Nov 04 '10 at 21:28
  • @Tokk, yup saw that. Changed my answer to say it's an alternative way! :) – Filip Ekberg Nov 04 '10 at 21:28
0

Set WindowStyle = none

Brad Cunningham
  • 6,402
  • 1
  • 32
  • 39