PopupButton is unexpectedly closing

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 9 years ago by Craig - Varigence, Inc.
Version: 10.1.0521
Platform: .NET 4.0
Environment: Windows 7 (32-bit)
Avatar
I'm hitting a case where the PopupButton control closes unexpectedly.

The scenario is that I have a .NET 4.0 datagrid with a template column. The cell template is a textblock but the editing template contains a PopupButton. Within the PopupButton is the ResizableContentControl, which is displaying a user control. Within the UserControl is a TreeView. I'm seeing that whenever I click in the ResizableControl area, unless I click perfectly on a TreeViewItem, the popup closes immediately and then reopens. My expectation would be that the popup would remain open until I actually select an item. I know that an item isn't being selected in the treeview since its SelectedItemChanged event doesn't fire.

My suspicion is that the UserControl is getting in the way somehow since I don't have the same problem if I add the TreeView directly in the ResizableControl. However, we do need the actual UserControl there, hence why I'm looking for a fix. I'll send over a sample app that should reproduce the scenario for you.

Thanks,

-Craig

Comments (4)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Thank you for the sample. This does appear to be a bug in the PopupButton, which we've corrected for the next maintenance release. In the interim, you can probably set the ClickMode to Press and still achieve the desired behavior.


Actipro Software Support

Posted 9 years ago by Craig - Varigence, Inc.
Avatar
I tried out your suggestion of switching the ClickMode but it didn't seem to help.

Can you give me more details on the fix you made to the PopupButton? Perhaps there'd be a way for me to incorporate that fix into my code currently? Or any chance I could get a private of the Shared DLL with the fix so I could try it and confirm that it resolves my issue? (I'm hitting a similar (but not 100% exact) issue in another app; the sample app is a simpler version of my actual problem so I'd really like to know if your fix works in my bigger application as well).

Thanks again,

-Craig

[Modified at 04/22/2010 03:38 AM]
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Can you please elaborate as to how it didn't help? Using the sample project you provided and only adding ClickMode="Press", it appears to fix the issue.

The issue stems from the fact that the button is getting a mouse down event, since nothing in the popup is handling the event (which produces another click). The ButtonBase (a native WPF class, that PopupButton derives from) has a handler for MouseLeftButtonDown that captures the mouse, and waits for a mouse up when using ClickMode.Release. The following class should reproduce the fix:
public class MyPopupButton : PopupButton {

    public MyPopupButton() {
        // Ensure MyPopupButton picks up PopupButton styles
        this.SetResourceReference(StyleProperty, typeof(PopupButton))
    }
    
    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) {
        if (this.IsPopupOpen) {
            this.IsPopupOpen = false;
            e.Handled = true;
            return;
        }

        base.OnMouseLeftButtonDown(e);
    }
}
The reason ClickMode.Press would fix the issue, is that the MouseLeftButtonDown does not capture the mouse and reopen the popup when the mouse is released. You can verify this with your sample (without any modifications), by hold the mouse down for a few seconds. You will see that the popup opens when you release the mouse, not immediately.

After a second look, we may not be able to include this fix in our code directly. At a minimum we'd probably have to make it an configurable option, as it would mean that clicking the button directly would also close the popup if it's open. We may be able to simply see if the mouse down is actually anywhere over the button, but we'll need to discuss this internally a little more.


Actipro Software Support

Posted 9 years ago by Craig - Varigence, Inc.
Avatar
So, apologies for the confusion. Setting ClickMode to "Press" does resolve this problem although I'm seeing another (likely related) issue. I'll open a separate bug report on the other issue to avoid confusion.

And BTW, thanks for the detailed information on the button down behaviors. I suspected something like that was the issue but I couldn't find the right way to handle it.

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

Add Comment

Please log in to a validated account to post comments.