4

Possible Duplicate:
Passing two command parameters using a WPF binding

I need that send two parameters to my RelayCommand like:

public RelayCommand<String,Int> MyCommand {get;set;} Or
public RelayCommand<EventArgument,String> MyCommand {get;set;}
0

2 Answers 2

13

Wrap them in an object:

public RelayCommand<MyModel> MyCommand { get; set; }

where MyModel will contain the two properties:

public class MyModel
{
    public int Id { get; set; }
    public string Name { get; set; }
}
Sign up to request clarification or add additional context in comments.

5 Comments

in fact i want send to mycommand :RelayCommand<EventArgument,ControlName>
@mtaboy, the way RelayCommand is defined, there is only one type you can pass. So if you want multiple types you will have to wrap them into a separate model as shown in my answer.
How can you set Id And Name in xaml code as MyModel ?
@mtaboy, your main view model could have a property of this type. Then you could use the CommandParameter with the correct binding syntax.
you are Right..But, How can I set Name And Id Property in Xaml code?
9

You can use a distinct model class in order to pass several parameters. And in order to initialize them, you can use xaml elements like this:

<Button Command="{Binding YourCommand}">
   <Button.CommandParameter>
      <YourNS:YourModel Id="{Binding PathForId}" Name="{Binding PathForName}"/>
   </Button.CommandParameter>
</Button>

This will construct a new YourModel object to pass to a command, and then will initialize its properties via bindings.

1 Comment

Actually this didn't end up working out for me in Silverlight. Instead I used the custom multibinding class mentioned in this article: codeproject.com/Articles/286171/MultiBinding-in-Silverlight-5 - no converter is needed, you just need to cast the object in to an object[].

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.