需要使用WindowsAPI
[DllImport("user32.dll", EntryPoint = "SetWindowLong")] private static extern int SetWindowLong32(HandleRef hWnd, int nIndex, int dwNewLong); [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] private static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, IntPtr dwNewLong); public IntPtr myHWND; public const int GWL_STYLE = -16; public static class WS { public static readonly long WS_BORDER = 0x00800000L, WS_CAPTION = 0x00C00000L, WS_CHILD = 0x40000000L, WS_CHILDWINDOW = 0x40000000L, WS_CLIPCHILDREN = 0x02000000L, WS_CLIPSIBLINGS = 0x04000000L, WS_DISABLED = 0x08000000L, WS_DLGFRAME = 0x00400000L, WS_GROUP = 0x00020000L, WS_HSCROLL = 0x00100000L, WS_ICONIC = 0x20000000L, WS_MAXIMIZE = 0x01000000L, WS_MAXIMIZEBOX = 0x00010000L, WS_MINIMIZE = 0x20000000L, WS_MINIMIZEBOX = 0x00020000L, WS_OVERLAPPED = 0x00000000L, WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, WS_POPUP = 0x80000000L, WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU, WS_SIZEBOX = 0x00040000L, WS_SYSMENU = 0x00080000L, WS_TABSTOP = 0x00010000L, WS_THICKFRAME = 0x00040000L, WS_TILED = 0x00000000L, WS_TILEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, WS_VISIBLE = 0x10000000L, WS_VSCROLL = 0x00200000L; } public IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, IntPtr dwNewLong) { if (IntPtr.Size == 8) { return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); } else { return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32())); } }
窗口Load事件中执行
myHWND = new WindowInteropHelper(this).Handle; IntPtr myStyle = new IntPtr(WS.WS_CAPTION | WS.WS_CLIPCHILDREN | WS.WS_MINIMIZEBOX | WS.WS_MAXIMIZEBOX | WS.WS_SYSMENU | WS.WS_SIZEBOX); SetWindowLongPtr(new HandleRef(null, myHWND), GWL_STYLE, myStyle);
正常调用最大化等方法就可以
this.WindowState = WindowState.Maximized; //SystemCommands.MaximizeWindow(this);
标签:dwNewLong,IntPtr,自定义,int,WS,最小化,WPF,nIndex,public From: https://www.cnblogs.com/tian2008/p/18098333