我想隐藏/禁用 WPF 窗口上的最小化和最大化按钮。
我尝试过使用 WinAPI
我在代码库中添加了以下类
internal static class WindowExtensions
{
// from winuser.h
private const int GWL_STYLE = -16,
WS_MAXIMIZEBOX = 0x10000,
WS_MINIMIZEBOX = 0x20000;
[DllImport("user32.dll")]
extern private static int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
extern private static int SetWindowLong(IntPtr hwnd, int index, int value);
internal static void HideMinimizeAndMaximizeButtons(this Window window)
{
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
var currentStyle = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, (int)(currentStyle & -65537 & -131073));
}
}
然后我尝试在该窗口的 SourceInitialised 方法上调用 HideMinimizeAndMaximizeButtons 方法。
这是我在互联网上找到的唯一解决方案。
有人可以建议任何其他解决方法吗?
答案 0 :(得分:0)
一种可能的解决方法是使用
隐藏整个标题栏<Window
WindowStyle="None"
并在需要时使用自定义按钮创建“程序关闭按钮”