3
我正在试验IronRuby和WPF,并且我想写我自己的commands。我所知道的下面是我所能想到的。如何在IronRuby中实现包含CLR事件的接口
class MyCommand
include System::Windows::Input::ICommand
def can_execute()
true
end
def execute()
puts "I'm being commanded"
end
end
但是ICommand接口定义了CanExecuteChanged事件。我如何在IronRuby中实现?
编辑:感谢凯文的响应
这里是什么工作基础上,27223变更集的DLR的。传递给can_execute和execute的值为零。
class MyCommand
include System::Windows::Input::ICommand
def add_CanExecuteChagned(h)
@change_handlers << h
end
def remove_CanExecuteChanged(h)
@change_handlers.remove(h)
end
def can_execute(arg)
@can_execute
end
def execute(arg)
puts "I'm being commanded!"
@can_execute = false
@change_handlers.each { |h| h.Invoke(self, System::EventArgs.new) }
end
def initialize
@change_handlers = []
@can_execute = true
end
end
这是一个很大的帮助。谢谢!我将工作解决方案代码添加到问题定义中。 – Ball 2009-08-24 13:23:10
太棒了!反过来,你的解决方案也帮助了我。请务必加入IronRuby邮件列表(如果您还不在):http://rubyforge.org/mail/?group_id=4359 – 2009-08-24 15:17:11