How can I capture the mouse when resizing a floating DocumentWindow or ToolWindow?

Docking/MDI for WPF Forum

Posted 11 years ago by Craig - Varigence, Inc.
Version: 12.2.0573
Avatar

Background:

I have an application that uses multiple DocumentWindows and ToolWindows. When I try to resize a floating DocumentWindow, I sometimes move my mouse cursor over a ToolWindow, whose inner control has mouse events to perform a drag and drop. As a result, I inadvertinely trigger a drag and drop during the DocumentWindow resize.

Problem:

I believe I can avoid this problem by capturing the mouse when resizing DocumentWindows and ToolWindows, but I don't see an event I can use to capture the mouse on resize start and release the mouse on resize end.

Question:

How can I capture (and later release) the mouse when resizing a floating DocumentWindow or ToolWindow?

 

Thanks,

-Craig

Comments (4)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Craig,

Unfortunately we don't expose any events for resizing.  But anyhow, in your case, it seems like the inner control should be using standard WPF drag/drop features instead of handling random mouse events over it.  Can you rework it to do that?


Actipro Software Support

Posted 11 years ago by Craig - Varigence, Inc.
Avatar

To my knowledge, my control is using standard WPF patterns for drag and drop. To be more specific, I use PreviewMouseDown and MouseMove events to know if the user intends to initiate a drag. This matches the technique Jaime Rodriguez describes in his Drag and Drop WPF article.

I expect that when resizing floating windows, the mouse is automatically captured to prevent underneath controls from intercepting mouse events (whether for D&D or any other reason). 

Questions:

  1. Using Snoop, it appears that resize occurs by dragging the floating window's WindowInner{x}Border, where x is Left, Top, Right, or Bottom. Assuming that's the case, is there a way I can access those Rectangles so I can attach the appropriate event handlers and have the mouse captured on MouseDown and released on MouseUp?
  2. I experimented with using a RaftingWindow style to capture MouseDown events on a floating window. I figured if I could at least determine that the user is clicking on the window, then I could try to determine if they're at the window's edge and capture the mouse if appropriate. However, the MouseDown never fired. Is RaftingWindow the right style type to use to capture mouse downs for floating windows?
Thanks,

-Craig

[Modified 11 years ago]

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Craig,

I'm not sure a mouse capture would be good here.  The reason being that for rafting windows, we actually call the Windows API and start a resize operation via that.  So the system is handling it from that point on, not WPF.

I believe the WindowControl that is in RaftingWindow is what actually gets the mouse.  It handles its OnPreviewMouseLeftButtonDown method and raises a DragResizing event when a resize start is detected.  RaftingWindow handles that and does the above-mentioned logic to start the actual resize via Windows API.

I still don't understand how the mouse down is able to start your drag/drop code though.  If the mouse is over the rafting window when it is pressed, how would that mouse down event get to your other control elsewhere to tell it to prep for a drag?


Actipro Software Support

Posted 11 years ago by Craig - Varigence, Inc.
Avatar

Your last question (regarding how the mouse down event could even be interferring) got me down the right path. Both in Jaime's example and in my code, the MouseMove event assumes that if the mouse button is down, then we're good to go for D&D. But both samples neglected to consider that the mouse button could be down due to a different source, such as the floating window, in which case D&D shouldn't begin.

Thanks again,

-Craig

The latest build of this product (v24.1.1) was released 21 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.