我认为“命令方法”是 CompositeCommand。
CompositeCommand 是 ICommand 的一个实现,因此它可以绑定到调用程序。 CompositeCommands 可以连接到多个子命令;当 CompositeCommand 被调用时,子命令也被调用。
CompositeCommands 支持启用。 CompositeCommands 侦听其连接的每个命令的 CanExecuteChanged 事件。然后它引发这个事件通知它的调用者。调用者通过在 CompositeCommand 上调用 CanExecute 对此事件做出反应。 CompositeCommand 然后通过对每个子命令调用 CanExecute 再次轮询其所有子命令。如果对 CanExecute 的任何调用返回 false,CompositeCommand 将返回 false,从而禁用调用者。
(Prism 4.0 自述文件第 9 章:松散耦合组件之间的通信)
例子:
public class MyViewModel : NotificationObject
{
private readonly CompositeCommand saveAllCommand;
public ArticleViewModel(INewsFeedService newsFeedService,
IRegionManager regionManager,
IEventAggregator eventAggregator)
{
this.saveAllCommand = new CompositeCommand();
this.saveAllCommand.RegisterCommand(new SaveProductsCommand());
this.saveAllCommand.RegisterCommand(new SaveOrdersCommand());
}
public ICommand SaveAllCommand
{
get { return this.saveAllCommand; }
}
}