Detect the end of a window drag in WPF and WindowChrome
-
I have a main application window and a floating WPF window. The user can drag the floating window over the main window in order that it docks. I need to detect the end of the drag operation. How do I do this? I am using Window Chrome to allow me to insert a drop down menu into the floating window's title bar. The usual way to detect a drag end is to wait for the WM_WINDOWPOSCHANGED message. Unfortunately Window Chrome seems to prevent this being sent. (It is sometimes sent, but not always.) I can enable hit tests for the window but that disables drag operations. Of course I can detect the LocationChanged event, but that is sent during a drag and not at the end. I could start a background thread on the first LocationChanged event to monitor when the mouse left button is not pressed (via a user32 call). I have tested this and it works, but it seems a bit clunky. I have hooked into the window's message loop but there is nothing that is of use. WindowChrome seems to filter out many messages especially in the non client area, and messages for the mouse key down and up are not sent.