Databinding with WPF and Silverlight

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

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

Thanks,
-John

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs