Binding to CheckableCommandParameter.Tag

Ribbon for WPF Forum

Posted 11 years ago by Tim Mawson
Version: 4.0.0456
Avatar
I've a simple Ribbon which contains a button wired up to a command that normally takes a parameter, the value of which is set via a binding:

<Button Command="MyCommand" CommandParameter="{Binding MyValue}"/>

Using a ribbon button means that it sends a CheckableCommandParameter to the command, which is fine since I need the button to be checkable anyway, however I cannot work out how to send the command the value from the binding source along with the CheckableCommandParameter.

I thought I might need something like:

<ribbon:Button Command="MyCommand">
<ribbon:Button.CommandParameter>
<CheckableCommandParameter Tag="{Binding MyValue}"/>
<ribbon:Button.CommandParameter>
</ribbon:Button>

However, it seems that it isn't possible to bind to the Tag property. Is there a way of doing something like this that I've overlooked? Or does use of CheckedCommandParameter mean that I can no longer send a value to the command via a binding?

Many Thanks

Tim Mawson
i2 Ltd.

Comments (2)

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

Correct, you probably can't bind to CheckedCommandParameter props since it is not in the logical tree. I know I've seen articles of why this is so, but I don't have any links at the moment that I can post.

The problem comes down to WPF's commands still needing more design enhancements by Microsoft. We were one of the pioneers of using the command parameters to allow modification of checked states, values, etc. Now if you search on WPFpedia, you'll see a bunch of similar implementations by others for doing advanced things with commands. However really that sort of thing should be built in.

One idea for a workaround... maybe bind to the Button.Tag property and in your handler case the e.OriginalSource to Button and get the Tag value.

Alternatively have your value implement ICheckableCommandParameter if you do need the checking capabilities.


Actipro Software Support

Posted 11 years ago by Tim Mawson
Avatar
Thanks for the response. In the end I was able to use the CheckedCommandParameter as intended and obtains access to my parameter via the command handling class. I'll make a note of your useful work-arounds if I become unstuck again.
The latest build of this product (v2019.1 build 0683) 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.