DocumentWindow click/drag problem

Docking/MDI for WPF Forum

Posted 7 years ago by Kasper
Version: 12.1.0561
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

Hi guys,

I've been having this problem for many months now and I simply can't find a way to reproduce it. The problem will occur when I change between open documents by clicking on their tabs. 9 out of 10 times, it just works, but on some occasions, the control will interpret the click as drag operation, so when I move the mouse after having clicked the tab, the tab follows the mouse, as if I'm trying to move/float it. I _think_ that this might occur if my application is doing something else in the background on another thread, e.g. with a BackgroundWorker, but as you can imagine, this is pretty difficult to reproduce. 

At one point I suspected the code I have in PrimaryWindowChanged was the problem, because they did some time consuming processing (no more than ~50-100 ms though), but I have tried putting in a huge Thread.Sleep() in a sample app and this doesn't do the trick.

I have spent many hours trying to make a sample, or at least get my own application to do this consistently, but with no luck - the bug is very periodic. Any suggestions on how to get around this problem would be _highly_ appreciated. I'm desperate, to say the least, so I'm willing to try pretty much anything. Hope you will help :)

Comments (3)

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

Hi Kasper,

If the left mouse button is up before moving the mouse then the window shouldn't drag. If it seems to happen when something else is working in the background then you may want to check if process is doing something that captures the mouse. This could result in the mouse button being released after the mouse is captured by the other process causing the window to never receive the mouse button up event that would signal the drag shouldn’t happen.


Actipro Software Support

Posted 7 years ago by Kasper
Avatar

Okay, ~3 more hours of careful testing finally lead me to the real problem - calls to a DoEvents() method, e.g. like the one found here: http://stackoverflow.com/questions/4502037/where-is-the-application-doevents-in-wpf. When I change between two documents, I sometimes have to wait for one BackgroundWorker to finish before starting another one, because they might add stuff to the same resource. Therefore I did something like this:

while(BackgroundWorker1.IsBusy)
	DoEvents();
BackgroundWorker2.RunWorkerAsync();

 This worked very well for me with WinForms, and while I know that DoEvents() is not a part of WPF by design, it is working pretty good here too, except for this weird click-drag-bug. I'm not really sure why it messes up anything for DocumentWindow's though? Any suggestions on how to get around this problem? :)

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

Hi Kasper,

It's hard to say why DoEvents causes things to break down, but DoEvents calls are not good design to have, even in WinForms.  What you should be doing instead is changing your design such that your BackgroundWorker1 has a RunWorkerCompleted event handler in which you kick off your BackgroundWorker2 instead.  If it's a conditional thing, you can always set a flag somewhere that you examine in your event handler.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.