# WPF: registering a routed event

**URL:** <https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802>\
**Category:** IronRuby\
**Created:** [February 9, 2009, 12:46am UTC](https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802 "2009-02-09T00:46:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 9, 2009, 12:46am UTC](https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802/1 "2009-02-09T00:46:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 9, 2009, 1:29am UTC](https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802/2 "2009-02-09T01:29:37Z")

</div>

b.click { puts “clicked!!” }

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

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] 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

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 25, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802/3 "2009-02-25T20:03:07Z")

</div>

FYI, Tomas’s latest patch ([Code Review: EventsAndSites5 - IronRuby - Ruby-Forum](http://www.ruby-forum.com/topic/179668))  
expands IronRuby’s .NET event support to:

def handler a,b  
puts ““handler: #{a} #{b}””  
end

c = C.new

# using a block:

h = c.on\_foo { |a,b| … }  
c.on\_foo.remove(h)

# using a method object:

h = method(:handler)  
c.on\_foo.add(h)  
c.on\_foo.remove(h)

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Jimmy  
Schementi  
Sent: Monday, February 09, 2009 6:28 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] WPF: registering a routed event

We only have blocks/lambda-\>event handlers working. Passing a method  
handle is on the list, but not done yet. Feel free to post a bug on  
RubyForge to make sure we get around to it.  
[http://rubyforge.org/tracker/?func=add&group\_id=4359&atid=16798](http://rubyforge.org/tracker/?func=add&group_id=4359&atid=16798)

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] 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

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 10, 2009, 3:50am UTC](https://www.ruby-forum.com/t/wpf-registering-a-routed-event/159802/4 "2009-02-10T03:50:36Z")

</div>

We only have blocks/lambda-\>event handlers working. Passing a method  
handle is on the list, but not done yet. Feel free to post a bug on  
RubyForge to make sure we get around to it.  
[http://rubyforge.org/tracker/?func=add&group\_id=4359&atid=16798](http://rubyforge.org/tracker/?func=add&group_id=4359&atid=16798)

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] 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
