我有以下使用 Prism 库创建的 DelegateCommand。
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);
}
}
我已经绑定MyButtonClickCommand
到 XAML 文件中的按钮。
<Button Content="Click me"
Command="{Binding MyButtonClickCommand}"/>
但我想对另外两个按钮使用相同MyButtonClickCommand
的按钮,而不是创建两个额外的 DelegateCommands MyButtonClickCommand1
& MyButtonClickCommand2
。
所以我想要添加string1
和integer_number1
作为参数,并在不同的按钮上调用相同的 ICommand,如下所示
<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)}"/>