【发布时间】:2011-10-20 01:28:15
【问题描述】:
在 XAML 中使用 ICommands 时,WPF 使用 CanExecute 方法来启用或禁用与命令关联的控件。但是如果我从程序代码中调用Execute 怎么办?我应该先检查CanExecute 以确保命令可以执行,还是应该Execute 为我处理这个检查?
换句话说,我应该这样做:
if (someCommand.CanExecute(parameter, target))
someCommand.Execute(parameter, target);
或者只是这样:
someCommand.Execute(parameter, target);
【问题讨论】:
-
为什么不把这部分作为 Execute() 的一部分?
标签: c# .net wpf icommand routed-commands