# Silverlight.rb

**URL:** <https://www.ruby-forum.com/t/silverlight-rb/181556>\
**Category:** IronRuby\
**Created:** [January 13, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/silverlight-rb/181556 "2010-01-13T19:49:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randall\_Sutton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/85e7bf/32.png) [@Randall\_Sutton](https://www.ruby-forum.com/u/Randall_Sutton)\
**Post date:** [January 13, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/silverlight-rb/181556/1 "2010-01-13T19:49:32Z")

</div>

I would like to use the Wpf.build method contained in the silverlight.rb  
file. Currently I can only find this file in the photoviewer app from  
2008 for what looks like Silverlight 2. Is there an updated version of  
this file? I noticed it isn’t contained in the 1.0RC1 download.

Thanks,  
Randall

---

<div class="post-metadata">

**Author:** ![Randall\_Sutton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/85e7bf/32.png) [@Randall\_Sutton](https://www.ruby-forum.com/u/Randall_Sutton)\
**Post date:** [January 20, 2010, 9:23am UTC](https://www.ruby-forum.com/t/silverlight-rb/181556/2 "2010-01-20T09:23:00Z")

</div>

Silverlight.rb has actually been embedded in the  
Microsoft.Scripting.Silverlight.dll (as init.rb) and is loaded  
automatically, but I didn’t include Wpf.build, so the version you have  
in the photoviewer app is the latest, so use at your own risk. It could  
possibly be added for the final release, or put in an external helper  
file. Let me know if it works for you currently.

~Jimmy

---

<div class="post-metadata">

**Author:** ![Randall\_Sutton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/85e7bf/32.png) [@Randall\_Sutton](https://www.ruby-forum.com/u/Randall_Sutton)\
**Post date:** [February 11, 2010, 1:29am UTC](https://www.ruby-forum.com/t/silverlight-rb/181556/3 "2010-02-11T01:29:40Z")

</div>

I ended up just taking the idea and making my own version.

class Wpf  
def self.create(t,args={},&b)  
# create an instance of the class  
obj = t.new

```
      # assign all the args
      args.each_pair do |k,v|
          obj.send("#{k.to_s}=",v)
      end

      # define the add method if it doesn't have one
      if !(obj.respond_to? :add) && (obj.respond_to? :children)
          obj.instance_eval('def add(t,args={},&b); obj = 

```

Wpf.create(t,args,&b); self.children.add(obj); obj; end;’)  
end

```
      # call the create method if there is one
      if obj.respond_to? :create
          obj.create
      end

      # execute the block against the instance
      obj.instance_eval(&b)
      obj
  end

```

end

Not as complex as the other, so I might be missing something. So far  
this has worked great and I added ability to have a create method so if  
you are constructing a class that inherits from a control you could do  
some initialization before the block is executed.

Thanks,  
Randall
