WPF中ICommand接口 的一个设计问题
public interface ICommand
{
// Summary:
// Occurs when changes occur that affect whether or not the command should execute.
event EventHandler CanExecuteChanged;
bool CanExecute(object parameter);
void Execute(object parameter);
}
// Defines an object that knows how to invoke a command.
public interface ICommandSource
{
// Summary:
// Gets the command that will be executed when the command source is invoked.
ICommand Command { get; }
object CommandParameter { get; }
IInputElement CommandTarget { get; }
}
MSDN:
Normally, a command source will listen to the CanExecuteChanged event on the command. This informs the command source when conditions change on the command target, such as loss of keyboard focus. The command source can then query the command using the CanExecute method.
按照MSDN中的解释,当CanExecuteChanged事件发生时,ICommandSource会调用ICommand的CanExecute方法来检测是否可以执行命令。如果是这样,这里的这个事件名取为:类似“CanExecuteConditionChanged”不是更好吗?
因为CanExecuteChanged发生,使用者的第一感觉就是CanExecute从false变到true或者由true变到false了。
关于这个设计问题,我想不出原因,所以希望高人解释下。:)
另外,还有一个小问题,MSDN中说到:
In the Windows Presentation Foundation (WPF) commanding system, the CommandTarget property on a ICommandSource is only applicable when the ICommand is a RoutedCommand. If the CommandTarget is set on a ICommandSource and the corresponding command is not a RoutedCommand, the command target is ignored.
那么,设计这个属性会不会有点多余?虽然我觉得加上也是好的。
- 在ASP.NET应用启动的时候初始化的几种方法
- [C#6] 8-异常增强
- 信息超新星的诞生
- jquery mobile 移动web(2)
- [腾讯社区开放平台].NET SDK基于New BSD协议开源
- IIS7.5上的REST服务的Put操作发生HTTP Error 405.0 - Method Not Allowed 解决方法
- 使用 asp.net mvc和 jQuery UI 控件包
- jquery mobile 移动web(1)
- WordPress Plugin Boilerplate:一个WordPress 插件开发模板(框架)
- [C#6] 5-自动属性增强
- React多页面应用1
- jQuery操作Select
- MSDN杂志上的Windows Phone相关文章
- WCF Data Service工具包
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 如何利用SystemTap统计函数执行耗时详解
- 关于安装linux redhat后无法使用yum命令安装gcc-c++问题的解决过程
- 基于代码的自动化和无代码自动化
- Java Stream中map和flatMap方法
- 关于Apache shiro实现一个账户同一时刻只有一个人登录(shiro 单点登录)
- 视频上云安防视频云服务平台EasyCVR通过海康sdk协议接入多路设备拉流时出现部分设备拉流不稳定是什么原因?
- Centos6.x服务器配置jdk+tomcat+mysql环境(jsp+mysql)
- Linux的压缩和解压缩的方法总结
- RTSP/GB28181/HIKSDK/Ehome协议视频融合平台EasyCVR编译C++报参见“XXX”的声明错误
- 详解 Linux 常用目录的作用
- CentOS6环境下搭建路由器的方法
- centos7下NFS使用与配置的步骤
- 基于DOM4J的XML文件解析类
- Win7安装和配置Apache2.4服务器的详细方法
- shiro会话管理示例代码