PopupButton and strange focus/drag behavior

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 11 years ago by David Mullin
Avatar
I'm using a PopupButton on a window - when I close the popup (either by clicking an "Ok" button on the popup, or by clicking off of the popup), something strange happens to the mouse capture. If I then mouse over another window in my application, it leaps to the front. If I mouse over something that does Drag & Drop, that ends up happening.

I don't know if I can make a simple reproduction, but if you need one, I can try.

Also (but presumably unrelated to this), how is the best way to programatically close the popup? I was originally just setting the IsPopupOpen property to false, but I see that there is a ClosePopup command. However, when I call ClosePopup.Execute(null, this), nothing happens. Am I calling it wrong, or is it that I need to have a CanExecute handler?

[Modified at 04/21/2009 02:01 PM]

Comments (4)

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

Unfortunately, we would need a sample. I tried running through some similar scenarios in our Sample Browser, but was not able to reproduce it.

There is a QuickStart under the Shared Library section of the Sample Browser that shows how to use the ClosePopup command. If you still can't get that work, then please send over a sample for that also.


Actipro Software Support

Posted 11 years ago by David Mullin
Avatar
OK, I figured out what it really is.

I'm using a DragDrop helper class that traps MouseDown/MouseUp/MouseMove events. When it sees a MouseDown, it starts paying attention, and when it sees a MouseUp, it stops paying attention.

What is happening is that I'm getting the MouseDown when the PopupButton is clicked, but I am not getting the MouseUp. As a result, when the popup closes, the underlying screen still thinks that the drag is going on.

Is this clear?

I presume that this is happening because the PopupButton is capturing the Mouse or some such. The DragDrop helper class is ignorant of context, and just listens to messages - is there any generic event that it could listen for to tell when this sort of thing has happened? Worse case, do you think just handling the PopupOpened routed event (and treating that as a MouseUp) would work?

As to closing the popup - the exampe in the QuickStart tie the ClosePopup command to a button in XAML. I'm trying to figure out how to best close the popup from code. I'm currently just saying "IsPopupOpen = false;" - is that the right way, or should I do something else (like fire the command). And, if the right way is to fire the command, how do I do that in code? I.e., something like ClosePopup.Execute(null, this);
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

You may be able to listen to the PopupOpened/PopupClosed events. Another option might be to listen for the Mouse.GotMouseCapture and Mouse.LostMouseCapture events. I'm not exactly sure which would be best for your situation though.

As for closing the Popup, you can certainly set the IsPopupOpen to false. The ClosePopup command is meant to be used by a Button inside the Popup to allow the end-user the ability to close a Popup that stays open. It sounds like setting IsPopupOpen is what you need.


Actipro Software Support

Posted 11 years ago by David Mullin
Avatar
Excellent - thanks!

I actually went ahead and tried trapping the PopupOpened event and treating that the same as ButtonMouseUp, and that seemed to work. The Mouse.Got/Lost capture events might be better - at least, they would be more generic (since the PopupOpened event is specific to the PopupButton). I'll try those.

Again, thank you for the continuous excellent support.

David
The latest build of this product (v2019.1 build 0683) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.