DragMove() and Maximize

Viewed 10229

I have a problem with my custom window (AllowTransparency, WindowStyle=None) in WPF. DragMove() method works good, but when I maximize window, or it maximizing automatically by Windows 7 Aero Snap, this method does not work at all. So I can't unsnap window with mouse drag and return it state to WindowState.Normal. Left and Right Aero Snap works good, I can snap and unsnap window without a problem. But when it maximized, nothing works except Win+Down combination. Maybe somebody knows how to solve this problem or where can I find other ways to do proper DragMove of custom window with working Aero Snap features?

6 Answers

The DragMove() method only works in the titlebar of the form so use:

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);

public static void StartDrag(Window window)
{
    WindowInteropHelper helper = new WindowInteropHelper(window);
    SendMessage(helper.Handle, 161, 2, 0);
}

Dont forget to add System.Windows.Interop

Related