禁用最小化按钮,但保持交叉和最大化按钮 - WPF,C#

Bub*_*d86 2 c# wpf

我想知道如何禁用最小化按钮,但保持最大化/恢复按钮和关闭按钮(红色"X").

这是我想要的右上方窗口按钮的图像:

在此输入图像描述

Bla*_*ter 6

您可能需要在此处使用PInvoke.基本上你正在导入SetWindowLong和GetWindowLong函数,并使用它的句柄(hwnd)将相应的标志设置到Win API窗口

private const int GWL_STYLE = -16;
private const int WS_MINIMIZE = -131073;
[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 static void CanMinimize(Window w)
{
  var hwnd = new WindowInteropHelper(w).Handle;
  long value = GetWindowLong(hwnd, GWL_STYLE);
  SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MINIMIZE));
} 
Run Code Online (Sandbox Code Playgroud)