eventToCommand pass eventargs + object

Topics: Feature requests
Jun 13, 2012 at 9:31 AM
Edited Jun 13, 2012 at 9:35 AM


maybe very simple question: How can i add another object to the param and handle it in the onexecute of the command, sth. like this:


    private void OnTestExecute(KeyEventArgs e, string bla)


Is this possible? If yes, how looks the command definition in VM and the trigger in XAML?


Edit: I know the possibility to have an extra poperty on the viewmodel which binds to the string. Just want to know if it is possible to avoid this.

Jun 13, 2012 at 9:46 AM

This is not possible. The command only accepts one parameter, so this will be very hard. What kind of parameter would you like to pass? Can't this be bound to the VM somehow?

The problem is that you are also interested in the KeyEventArgs, otherwise you could create a tuple<> object.

Jun 13, 2012 at 10:01 AM
Edited Jun 13, 2012 at 10:01 AM

The simplet approach would be to have a Edit.Text and react to the Enter Key and pass the text.  But I have to say this edit is not bound to any model data, and there would be no need to save the string in a property.

I saw the KeyPressToCommand, but sadly there is no CommandParameter property.

Ok, maybe I should use just a property in vm.


Another question, is it possible to get the content of a button in a eventtocommand?

Jun 13, 2012 at 10:06 AM

1) Maybe we can implement a command parameter for KeyPressToCommand. I will look into this.

2) No, you cannot get the content of a button in the EventToCommand. You probably want this to know what button was clicked, but using the content for that is really bad. It is better to use the tag or something like that. But even then, there is no sender, so this will be hard to accomplish.

Jun 13, 2012 at 11:03 AM

1) Ok thanks, we will see.

2) Yes, you are right. I think in such special cases I will use codebehind.

Jun 13, 2012 at 1:22 PM
Edited Jun 13, 2012 at 1:27 PM

In addion to 1): Now I just use a KeyBinding (System.Windows.Input.InputBinding) like that:

<dxe:TextEdit Name="textEdit1">
     <KeyBinding Key="Enter" Command="{Binding Test}" CommandParameter="{Binding Text, ElementName=textEdit1}" />

By the way, what is the difference between your KeyPressToCommand and  the InputBinding class? Seems to offer the same things?

Jun 13, 2012 at 1:25 PM

InputBinding is only supported on some classes and only available in WPF. The KeyPressToCommand can be used in any framework (like almost everything in Catel).

Keep in mind that most CommandParameter objects are not bindable.

Jun 13, 2012 at 1:42 PM

In deed, I see. I looked at your source code for the keyPresstoCommand, think there would be no problem to add a commandparameter.

By the way, thanks to your great support.

Jun 13, 2012 at 1:50 PM

Please create an issue with the request here:


I can't keep up with all the feature requests in the discussions.

Jun 18, 2012 at 6:59 AM

I saw the issue is closed. Where can I get the ne code? I downloaded the newest source code, buit there is no command parameter in the keypressToCommand.

Jun 18, 2012 at 7:06 AM

You can get beta versions of Catel via this mechanism:


If I remember correctly, this feature is already in there. If not, I will release a new nuget deployment tonight.