3

I'm trying to hide/remove the close button on my MahApps MetroWindow without success.

I've tried with this code:

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);

private void Window_Loaded(object sender, RoutedEventArgs e)
{
        var hwnd = new WindowInteropHelper(this).Handle;
        SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}

I've also set up some properties:

...ShowTitleBar="False" WindowStyle="None" ResizeMode="NoResize" 
    Loaded="Window_Loaded" ...

So the Window_Loaded is trigger correctly but the code of this question seems not working.

This is the actual result:

enter image description here

Why the button don't disappear? What I'm doing wrong?

Community
  • 1
  • 1
Bender
  • 523
  • 6
  • 21
  • It works just fine when I try it. But this does not look like a normal Window class, hard to guess where ShowTitleBar comes from. – Hans Passant Sep 05 '15 at 13:19
  • I'm using mahapp metro framework, maybe this is the problem? – Bender Sep 05 '15 at 13:24
  • Yes, that's the problem. Clearly you need to update your question. – Hans Passant Sep 05 '15 at 13:27
  • Uhm well, I honestly do not know who provide more details. I asked about git support mahapp to take a look at this question, maybe their can deal with the problem. – Bender Sep 05 '15 at 13:29

1 Answers1

24

You can use the ShowCloseButton dependency property of the MetroWindow.

punker76
  • 14,326
  • 5
  • 58
  • 96