How to pass several parameters to RelayCommand?

Possible duplicate:
Passing two command parameters using WPF binding

I need to send two parameters to my RelayCommand, for example:

public RelayCommand<String,Int> MyCommand {get;set;} Or public RelayCommand<EventArgument,String> MyCommand {get;set;} 
+4
source share
2 answers

Wrap them in an object:

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

where MyModel will contain two properties:

 public class MyModel { public int Id { get; set; } public string Name { get; set; } } 
+12
source

You can use a separate model class to pass in several parameters. And 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 create a new MyModel object to pass the command to, and then initialize its properties using bindings.

+7
source

Source: https://habr.com/ru/post/1383201/


All Articles