关于command的绑定有两种方式
1, 通过prism 的delegatecommand 类,该类仍然继承自ICommand
下面是示例程序:
private DelegateCommand<string> myDelegateCommand; //首先声明delegate command字段
public DelegateCommand<string> MycDelegateCommand //声明对应的属性,其中的泛型表示 //通过 UI界面的 commandparameter //要传递的参数是string 类型
{
get
{
if (myDelegateCommand==null)
{
myDelegateCommand = new DelegateCommand<string>(method, mymethod);// 此处是为了声明一个delegate command 类型的实例,其中携带了两个委托,第一个委托对应的方法是为了响应对应的command指令,第二个委托是为了设置一个条件,当条件返回true时,command 指令有效,如果返回值是false,则command指令无效
return myDelegateCommand;
}
else
{
return myDelegateCommand;
}
}
}
public void method(string a) //该处传入的string a 对应的是commandparameter的值。
{
MessageBox.Show(a);
}
public bool mymethod(string b)
{
return false;
}