如何解决接口实现在函数中有一个额外的参数
| 这是ICommand成员的定义:http://msdn.microsoft.com/zh-cn/library/system.windows.input.icommand.execute.aspx 签名是:
void Execute(
Object parameter
)
它由RoutedCommand使用以下签名实现(http://msdn.microsoft.com/zh-cn/library/system.windows.input.routedcommand.execute.aspx):
public void Execute(
Object parameter,IInputElement target
)
RoutedCommand如何在成员函数中使用额外的参数(IInputElement)实现ICommand?
解决方法
它使用显式接口实现来“隐藏”采用单个参数的
ICommand.Execute
方法。带有两个参数的Execute
方法不是ICommand.Execute
的实现。
public class RoutedCommand : ICommand
{
public void Execute(object parameter,IInputElement target)
{
// ...
}
// explicit interface implementation of ICommand.Execute
void ICommand.Execute(object parameter)
{
// ...
}
}
,ICommand.Execute()接口方法是显式实现的。文件在这里。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。