I'm experimenting with IronRuby and WPF and I'd like to write my own commands. What I have below Is as far as I can figure out.
class MyCommand
include System::Windows::Input::ICommand
def can_execute()
true
end
def execute()
puts "I'm being commanded"
end
end
But the ICommand interface defines the CanExecuteChanged event. How do I implement that in IronRuby?
Edit: Thanks to Kevin's response
Here's what works based on the 27223 change set of the DLR. The value passed in to can_execute and execute are nil.
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