简体   繁体   中英

How to hide the close button in a MahApps.Metro window?

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:

在此处输入图片说明

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

您可以使用ShowCloseButton中的依赖属性MetroWindow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM