I have made a test app with XAML + WPF + IronRuby event handlers
(IronRuby revision 76). The code of the Ruby-part (EventManager.rb) is
below. Due to lack of other working mechanisms of connecting the
Ruby-methods to the WPF-events, I ended up in passing the widget
reference to Ruby in a global variable and then using the closure-syntax
to connect the delegates on Ruby-side.
All three events work ok and the App runs, but only with following event
names:
CLR name of the event Name of event seen in IronRuby
"Click" "click"
"Loaded" "loaded"
"MouseEnter" "MouseEnter"
Notice that whereas "Click" and "Loaded" mapped to their lower-case
equivalents, the "MouseEnter" event connected only if it was written in
the original capital form "MouseEnter" on IronRuby-side. The most
logical alternative "mouseEnter" caused MethodMissing. I suspect such
inconsistency in the name-mapping cannot be intentional.
Robert Brotherus
Software architect
Email: [EMAIL PROTECTED]
www.napa.fi
------------------------- EventManager.rb: -------------------------
# Reference the WPF assemblies
require 'PresentationFramework, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
require 'PresentationCore, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
SolidColorBrush = System::Windows::Media::SolidColorBrush
Colors = System::Windows::Media::Colors
module NWS
module COLOURBUTTON
class WidgetEventManager
def initialize(widget)
widget.click { |sender,args| self.click(sender,args) }
# CLR name: Click
widget.loaded { |sender,args| self.loaded(sender) }
# CLR name: Loaded
widget.MouseEnter { |sender,args| self.mouse_enter(sender,args)
} # CRL name: MouseEnter
end
def click(widget, args)
widget.content = widget.content.to_s + "X"
end
def mouse_enter(widget, args)
widget.background = SolidColorBrush.new(Colors.Red)
end
def loaded(widget)
widget.background = SolidColorBrush.new(Colors.Yellow)
end
end
end
end
WidgetEventManager.new($widget)
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core