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