我有一个无边框的 WPF 窗口。我已经使用 WinAPI 编写了调整大小/拖动功能,但它忽略了窗口的最小宽度和最小高度。如何执行这些值?
我的代码如下:
private void Resize(object sender, MouseButtonEventArgs e)
{
String resizeHandle = (sender as System.Windows.Shapes.Rectangle).Name;
ResizeDirection direction =
resizeHandle == "PART_RESIZEHANDLE_TOP" ? ResizeDirection.Top
: resizeHandle == "PART_RESIZEHANDLE_BOTTOM" ? ResizeDirection.Bottom
: resizeHandle == "PART_RESIZEHANDLE_LEFT" ? ResizeDirection.Left
: resizeHandle == "PART_RESIZEHANDLE_RIGHT" ? ResizeDirection.Right
: resizeHandle == "PART_RESIZEHANDLE_TOPLEFT" ? ResizeDirection.TopLeft
: resizeHandle == "PART_RESIZEHANDLE_TOPRIGHT" ? ResizeDirection.TopRight
: resizeHandle == "PART_RESIZEHANDLE_BOTTOMLEFT" ? ResizeDirection.BottomLeft
: resizeHandle == "PART_RESIZEHANDLE_BOTTOMRIGHT" ? ResizeDirection.BottomRight
: 0;
if (direction == ResizeDirection.Unknown)
throw new ArgumentException();
SendMessage(hwndSource.Handle, WM_SYSCOMMAND, (IntPtr)(61440 + direction), IntPtr.Zero);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);