This project has moved and is read-only. For the latest updates, please go here.

RelayCommand and more parameter

Jun 1, 2010 at 10:26 AM


I want to know if it's possible to use relaycommand with two, three... parameters.

In fact, I have several textbox that I must save in database. So, I don't know how I can send the content of textbox to modelview.

Any Ideas ?



Jun 1, 2010 at 12:01 PM


The fact that RelayCommand can accept only one parameter is in fact due to the ICommandSource and ICommand interface that is built in Silverlight and WPF. ICommandSource declares only one CommandParameter, and ICommand has Execute(object parameter) only.

In general however, this is not a problem. In your case, simply create a two way binding to string properties in your ViewModel. This way, the VM already has all the information it needs when the command is executed.

Hope that helps,


Mar 4, 2011 at 4:55 AM
Edited Mar 4, 2011 at 5:17 AM

Hi Laurent,

I have been using the MVVM Light toolkit for my Silverlight appilication.

I have a requirement wherein i have to pass the EventArgs as well as the CommandParamter to the VM. Basically I want to pass the keyEvents and an object to the VM. The VM will check if the correct keyEvents where sent, if yes then do certain operations on the object passed. The object here is a TabControl, hence am not able to bind the entire TabControl to some property in my VM. Also, cannot bind the Items property of TabControl to a collection of TabItems in VM since I have a couple of TabItems created in XAML while some would be created at runtime, on user interaction. Hence, if I try to bind the Items property in XAML it says "The property Items is set more than once".

From the discussion above I understand that passing only one parameter is a limitation of ICommandSource and ICommand interface. However, can you please suggest any workaround for the scenario above?