views:

50

answers:

3

I'm improving standart WPF TabControl. I want to add undocking functionality to it: user drags the page just outside the TabControl and this page undocks in the window. I want two events in this control - PageDragStart (raises when the page dragged outside) and PageDragEnd (raises when the page dropped outside)

I've got no problem with the first event.

But the second... OnDrop doesn't call, because the item dropped outside the tabcontol container. How can I know that it was dropped?

P.S. I want a universal control (so, undocking functionality shouldn't be connected and hardcoded with the window tabcontrol is placed or something like this)

A: 

I solved the problem - in rather brutal and unsafe way. But for it's gonna work as the temporary solution.

Well, when I'm raising PageDragStart event, I call Mouse.Capture(this, CaptureMode.SubTree); When the page is dropped somewhere - DoDragDrop throws different exceptions (COMException, NullReference (I couldn't find which object is null) and some others I don't remember). I catch exception and call PageDragEnd event (if the property IsPageDraggingOut set to true).

As far as you can see this solution is really dirty and bad. But it works.

So, any other ideas (or some ideas how to work with Mouse.Capture properly)?

xSeder
A: 

try this

Chen Kinnrot
+1  A: 

Why use DoDragDrop at all? As I was reading your description, using Mouse.Capture by itself seemed the obvious solution:

  1. Handle OnMouseLeftButtonDown on the tab and start capture
  2. Handle OnMouseMove on the tab and update the cursor based on hit testing
  3. Handle OnMouseLeftButtonUp on the tab, and stop the capture and make the appropriate change

The reasons you might ever consider DoDragDrop over simple mouse capture are:

  1. Integration with Windows' OLE drag and drop so you can drag and drop between applications and technologies
  2. Modal nature of DoDragDrop call (which actually seems to be more of a disadvantage to me)
  3. Automated hit testing of targets
  4. Standardized "drop operation" API to allow unrelated applications to handle copy vs move, etc.

You apparently don't need the OLE integration or multi-application support and you want to customize the hit testing, so it seems that DoDragDrop has no advantages over directly handling the mouse capture.

Ray Burns