WPF不必禁用最大化窗口(不像的WinForms)一个天然的方式。因此,考虑以下关键点:
1.隐藏最大化按钮
使用WinAPI的是很长的路要走,但只用于隐藏最大化按钮。使用以下命令:以上仍允许最大化(例如,通过在窗口的标题双击)
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_STYLE = -16;
private const int WS_MAXIMIZEBOX = 0x10000;
private void Window_SourceInitialized(object sender, EventArgs e)
{
var hwnd = new WindowInteropHelper((Window)sender).Handle;
var value = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MAXIMIZEBOX));
}
2.操作手动最大化
该代码。
WPF对标题栏行为没有控制权。如果您想更改双击行为,则需要删除标题栏并创建自己的标题栏。看看MahApps.Metro - link to sample是如何完成的。之后,处理双击事件。
它不会禁用实际上最大化,并导致闪烁窗口。因此我不能将其标记为答案。 – 2013-11-25 21:34:04