I have the following DelegateCommand, created with the Prism library.
public class AddressModel : INotifyPropertyChanged
{
public ICommand MyButtonClickCommand
{
get { return new DelegateCommand<object>(FuncToCall); }
}
public void FuncToCall(object context)
{
//this is called when the button is clicked
Method1("string1", integer_number1);
}
}
I have already bonded MyButtonClickCommand
to a button in XAML file.
<Button Content="Click me"
Command="{Binding MyButtonClickCommand}"/>
But I would like to use the same MyButtonClickCommand
for 2 more buttons instead of creating two additional DelegateCommands MyButtonClickCommand1
& MyButtonClickCommand2
.
So what I want is to add string1
and integer_number1
as parameters and call the same ICommand on different buttons like below
<Button Content="Click me"
Command="{Binding MyButtonClickCommand("string1", integer_number1)}"/>
<Button Content="Click me 2"
Command="{Binding MyButtonClickCommand("string2", integer_number2)}"/>
<Button Content="Click me 3"
Command="{Binding MyButtonClickCommand("string3", integer_number3)}"/>
You can pass an instance of any class that could be declared in XAML
to the
CommandParameter
property of a Button:The MyCommandParameter instance is passed to the Execute handler method's argument: