# Databinding with WPF and Silverlight

**URL:** <https://www.ruby-forum.com/t/databinding-with-wpf-and-silverlight/135971>\
**Category:** IronRuby\
**Created:** [April 27, 2008, 9:55am UTC](https://www.ruby-forum.com/t/databinding-with-wpf-and-silverlight/135971 "2008-04-27T09:55:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [April 27, 2008, 9:55am UTC](https://www.ruby-forum.com/t/databinding-with-wpf-and-silverlight/135971/1 "2008-04-27T09:55:18Z")

</div>

Hi

Will plain ruby objects be able to participate in the WPF databinding  
scenario or I may be doing it wrong ? I’m asking because I tried the  
following and the C# class works but the ruby class doesn’t. If I  
replace  
Person.new with CSPerson.new it works.  
I can bind to arrays with simple types and I’ve tried binding to Name or  
name.

```
<Grid>

```

public class CSPerson  
{  
public CSPerson(int id, string name, int age){  
Id=id;  
Name=name;  
Age=age;  
}

```
public int Id{get; set;}
public string Name{get; set;}
public int Age{get; set;}

```

}

# get the necessary assemblies loaded for .NET

require ‘mscorlib’  
require ‘System, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘System.Xml, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘PresentationFramework, Version=3.0.0.0, Culture=neutral,  
PublicKeyToken=31bf3856ad364e35’  
require ‘PresentationCore, Version=3.0.0.0, Culture=neutral,  
PublicKeyToken=31bf3856ad364e35’  
require File.expand\_path(’./csperson.dll’ )

# include some namespaces for easy access

include System  
include System::Windows  
include System::Windows::Markup  
include System::Xml

class Person  
attr\_accessor :name, :age, :id

```
def initialize(id, name, age)
    @id, @name, @age = id, name, age
end

```

end

#run the application  
xaml\_path = “default.xaml”  
obj = XamlReader.load XmlReader.create(xaml\_path)

people = []  
people \<\< Person.new(1, “ivan”, 30)  
people \<\< Person.new(2, “jeff”, 25)  
people \<\< Person.new(3, “mark”, 38)  
people \<\< Person.new(4, “vicky”, 33)

obj.find\_name(‘list’).items\_source = people  
Application.new.run obj

Thanks  
Ivan

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [April 28, 2008, 4:16pm UTC](https://www.ruby-forum.com/t/databinding-with-wpf-and-silverlight/135971/2 "2008-04-28T16:16:14Z")

</div>

Ivan Porto C.:

> Will plain ruby objects be able to participate in the WPF databinding  
> scenario or I may be doing it wrong ? I’m asking because I tried the  
> following and the C# class works but the ruby class doesn’t. If I  
> replace Person.new with CSPerson.new it works.

This will definitely work in the future. We’ll revisit this  
post-RailsConf. I had this working a couple of years ago with RubyCLR:

[http://www.iunknown.com/2006/05/activerecord-an.html](http://www.iunknown.com/2006/05/activerecord-an.html)

Thanks,  
-John
