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

3

6

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!

Election answered 6/10, 2010 at 20:51 Comment(0)
E
4

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.

Election answered 6/10, 2010 at 20:57 Comment(0)
A
2

The 'correct' way to make a borderless window movable --> https://mcmap.net/q/1203908/-way-to-make-a-windowless-wpf-window-draggable-without-getting-invalidoperationexception

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

Allisan answered 7/3, 2012 at 22:0 Comment(1)
That's a good link but it doesn't have anything to do with my issue here. I had a runaway bubble event that was throwing it all out of whack. My dialog that popped up didn't even implement dragmove so there was no way to drag it around.Election
R
1

if you receive this exception when messagebox show complete. place Dragemove(); inside try and empty in catch.

Roberts answered 30/3, 2018 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.