Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf - transparent MainWindow and issues with DragMove "Can only call DragMove when primary mouse button is down."

I have a wpf project which uses transparent windows and I share this transparent window styling for my dialog windows and my mainwindow.

I am getting an error on my DragMove() event of my MainWindow AFTER I close a dialog window that uses the same window style. To make this even more strange this exception only occurs when I handle a mouseleftbutton event on a label in my Status Bar on the MainWindow. IF I swap out the label for a button and replace the mouseleftbuttondown with a click event I do not get the error.

The strange thing is that the dialog window that pops up does not implement dragmove, and I'm not dragging around my mainwindow either. Somehow dragmove gets called after my code execution returns to the mainwindow after a showdialog() call.

An easy fix for me currently is to swap my label for a button and wire up the click event instead.

However, I'm more interested in hearing about what causes this issue and why a click event works but the mouse one fails miserably.

My "StatusBar" is simply a stackpanel with labels and other stackpanels (which contain more labels).

Has anyone else fought this issue before? Would I need to implement some sort of mouseclick event handler override so that I can capture and cancel this exception from happening?

Repro code can be provided if needed. I got enough hits on dragmove here so I am hoping this is an easy one for somebody out there.

Thanks in advance for any help!

like image 634
TWood Avatar asked Oct 06 '10 20:10

TWood


2 Answers

my brain isn't working properly today. I forgot about routing of events in this scenario. I simply needed to set the Handled property on my routedevent that fired off when the mousebutton was down. Somehow I missed that in the debugger before posting the thread.

like image 75
TWood Avatar answered Nov 11 '22 08:11

TWood


The 'correct' way to make a borderless window movable --> https://stackoverflow.com/a/3275712/146032

Be sure to only call DragMove when triggered by event MouseLeftButtonDown and don't forget to handle the event using e.Handled=true;

like image 1
bithavoc Avatar answered Nov 11 '22 09:11

bithavoc