Ribbon Splitbutton with custom user control popup and need for on click stay open

Ribbon for WPF Forum

Posted 9 years ago by Ken Hanson
Version: 14.2.0611
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

You have a Attached dependency property called

ribbon:PopupControlService.StaysOpenOnClick="True"

That is honored by ContextMenuItems and the documentation seems to infer that it should be honored by usercontrol (and it's children) in a PopupButton's popup content.  However, it is not, this leads to some miserable issues when you have a radio button or some other clickable control in your custom usercontrol that should not cause the popup to close.

Because this is an Attachable dependency property is should be easy enough to honor this for any controls that raises the click event that you must be watching to determine if the popup should close or not.

Use of your attached property seems to be the best solution, if you have another solution or a work around for the problem in the meantime please let me know.

Best Regards,

Ken

Comments (6)

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

Hi Ken,

The attached property by itself doesn't actually do anything.  Our ButtonBase and ComboBox base controls expose that dependency property as a public StaysOpenOnClick property on their respective classes.  Then code inside those classes will not blur focus back to the main focus scope when the button is clicked, etc. if StaysOpenOnClick = false.  The property really only affects those instances it is set on and isn't inherited.

If you would like to email our support address with a new simple sample project that shows the problem you're having, we can have a look and make some suggestions on how to handle it.  In your email, please reference this thread and rename the .zip file extension of whatever you send so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Posted 9 years ago by Ken Hanson
Avatar

I will take some time and put together a simple sample.  I have to believe that others have struggled with this.  The only viable solution I can find is to trap the previewleftmousedown on any controls in my user control that have a click event and set the event handled as true.  This really make life painful.

Note that the StaysOpenOnClick is not just a simple DependencyProperty for ButtonBase and ComboBox but is also an Attached DependencyProperty on the PopupControlService. 

If you have an event that you are watching on a ribbon popup button that can see which control raised the click event (sender object) to determine when to close the popup then checking to see if the attched property ribbon:PopupControlService.StaysOpenOnClick="True" is attached to that control would be a very easy and nice way to give people who are using custom controls in ribbon popup content a way to control what they want to do inside their user controls.

Thanks

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

Hi Ken,

Controls will often move focus elsewhere or close popups if they are clicked while within a focus scope.  That is something that is hardcoded in many native WPF controls, in our own controls, and other third party controls. 

When we see that our property is set on our versions of ButtonBase and ComboBox, we specifically skip the code that restores focus outside of the focus scope or closes popup.  It's not something that can really be done externally by handling PreviewMouseLeftButtonDown and handling it because most controls actually require you to fully click (press and raise) within a control to be a true click.  The functionality feels awkward otherwise.  That's why it's mostly necessary for those writing custom controls to choose on their end not to move focus around, etc. if a property such as StaysOpenOnClick is assigned.


Actipro Software Support

Posted 9 years ago by Ken Hanson
Avatar

In my case I am not moving focus.  A usercontrol used as popup content that contains a standard radiobutton it will cause the popup to close when the radiobutton is clicked.  How would you work around this?

Thanks,

Ken

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

Hi Ken,

If you use Reflector on ButtonBase.OnLostMouseCapture (the native WPF one that RadioButton inherits), you can see that they call Keyboard.Focus(null) if not in the main focus scope.  That's likely what's causing it to happen here since Ribbon is like a ToolBar and is not in the main focus scope.  That's the exact sort of code we skip over in our own implementations when we set that StaysOpenOnClick property to true.

If you inherit RadioButton you could override OnLostMouseCapture and don't call the base method.  That will also have a side effect of preventing their internal SetIsPressed(false) call, which may or may not be a problem.  This sort of thing is why we rolled our own base classes that we could control better.


Actipro Software Support

Posted 9 years ago by Ken Hanson
Avatar

I will experiment a bit with the information you gave me and get back to you.  Thank you for the insight.

The latest build of this product (v24.1.1) 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.