[Ironruby-core] WPF: registering a routed event

Tomas Matousek Tomas.Matousek at microsoft.com
Sun Feb 8 19:17:29 EST 2009


b.click { puts "clicked!!" }

should do. We are going to enable more ways how to hook event handlers.

Tomas

From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Meinrad Recheis
Sent: Sunday, February 08, 2009 3:46 PM
To: ironruby-core
Subject: [Ironruby-core] WPF: registering a routed event

Hi all,

I seem to step in every hole there is on my IronRuby test drive. Using the latest git head I am failing to register a button click event in WPF:
>>> require "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
=> true
>>> require "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
=> true
>>> require 'PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
=> true
>>> b = System::Windows::Controls::Button.new
=> #<System::Windows::Controls::Button:0x0000064>
>>> def on_click o, args
... puts "clicked!!"
... end
=> nil
>>> b.add_Click( method(:on_click))
:0: can't convert Method into System::Windows::RoutedEventHandler (TypeError)
>>> h=System::Windows::RoutedEventHandler.new{|o, args| puts "clicked!!" }
=> #<System::Windows::RoutedEventHandler:0x000006a>
>>> h.Invoke(nil, nil)
clicked!!
=> nil
>>> b.add_Click(h)
:0: can't convert Method into System::Windows::RoutedEventHandler (TypeError)


Actually I would have expected b.add_Click( method(:on_click)) or b.add_Click( lambda {|o, args| ... } ) to work, just like it does in IronPython:


>>> clr.AddReference( 'WindowsBase')
>>> clr.AddReference( 'PresentationCore')
>>> clr.AddReference( 'PresentationFramework')
>>> import System
>>> from System import Windows
>>> from System.Windows import Controls
>>> from System.Windows.Controls import *
>>> b= Button()
>>> def on_click(o, args):
...   print "clicked!!"
...
>>> b.add_Click(on_click)
>>>

I hope, I am not starting to annoy you guys ;)
-- henon


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090208/38997d7b/attachment.html>


More information about the Ironruby-core mailing list