简体   繁体   English

如何在MahApps.Metro窗口中隐藏关闭按钮?

[英]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. 我试图隐藏/删除MahApps MetroWindow上的关闭按钮,但未成功。

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. 因此,Window_Loaded已正确触发,但此问题的代码似乎无法正常工作。

This is the actual result: 这是实际结果:

在此处输入图片说明

Why the button don't disappear? 为什么按钮不消失? What I'm doing wrong? 我做错了什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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