我试图隐藏/移除MahApps MetroWindow上的关闭按钮,但没有成功。
我已经尝试了以下代码:
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);
}
我也设置了一些属性:
...ShowTitleBar="False" WindowStyle="None" ResizeMode="NoResize"
Loaded="Window_Loaded" ...
Window_Loaded事件已正确触发,但是这个问题的代码似乎不起作用。
这是实际结果:
为什么按钮没有消失?我做错了什么?