My Life As A Blog

Ruby Tuesday #22 : First steps with IronRuby and Silverlight

with one comment

With the recent release of Silverlight 2 and the latest version of the Dynamic Languages SDK, now seemed like a good time to write a simple Silverlight application in Ruby.  Once you’ve got all the bits downloaded, installed and extracted, find yourself a fresh new folder and open a command prompt.  I should note that I put the scripts folder of the Dynamic Languages SDK on my path variable before opening the command prompt.  At the prompt type:

sl ruby <application_name>

replacing <application_name> with the name of your application.  To see it running type:

server /b

Navigate to index.html and there’s the app running.

Right – time to fiddle.  Open the app.xaml file and add a button.  Here’s my xaml file:

<UserControl x:Class="System.Windows.Controls.UserControl"
  <Grid x:Name="layout_root" Background="White">
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="100"/>
      <RowDefinition Height="100"/>
      <RowDefinition Height="*"/>
    <TextBlock x:Name="message" FontSize="30" Grid.Column="0" Grid.Row="0" />
    <Button Margin="4,4,4,4" FontFamily="Verdana" FontSize="18" Grid.Column="1" Grid.Row="0" 
Content="Push Me!" x:Name="rubyButton" />

Now, we just need to do something when the button is clicked.  Open the app.rb file and update the initialise method so it looks like this:

def initialize 
  message.text = "Welcome to Ruby and Silverlight!" do |sender, e| 
    message.text = "Hello World!" 

Reload your app, click the button and whoop with delight.  Worth looking at index.html in an editor – the documentation will prove helpful.


Written by remark

October 21, 2008 at 6:07 pm

One Response

Subscribe to comments with RSS.

  1. Nice blog…


    November 4, 2008 at 3:39 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: