.NET Coffee Break Show on IronRuby and Silverlight

I was just on a cool webcast called the .NET Coffee Break Show. I did a short show on getting started with IronRuby and Silverlight.

Because the show is supposed to be just 30 minutes or so, I didn’t get into my usual preaching about the Ruby programming language or why people should use a dynamic language. Instead I just stated the fact that I really like Ruby and I really like Silverlight and I especially like the combination of the two.

To get started with IronRuby, check out the getting started guide with IronRuby by Justin Etheredge.

Now, it’s not absolutely necessary to go through all of those steps to get started with IronRuby in Silverlight. Instead, just download the Silverlight Dynamic Languages SDK. Under the Releases tab, there are a handful of downloads. The one that you want is the one that has “Everything”. This includes the languages, samples, quick start templates and more.

Steps to get started:

1. Unzip the SDLSDK into a directory. I put mine in my public downloads directory for ease of access.

2. Open a command prompt, cd to the sdlsdk directory and run the script:

script\sl ruby demo

This will run the template to generate a starter Silverlight application with IronRuby as it’s language. You could substitute in python or jscript as well.

3. cd to the directory demo and run the script

..\script\server /b

This will run Chiron and then launch a new browser window pointing to the directory. Chiron will first package up the dynamic language files into the XAP and then host a simple web server.

4. Browse to the index.html file. You should see a simple page with “Welcome to Ruby and Silverlight!” displayed in the Silverlight instance.

image

5. Under demo/ruby, open the file app.xaml. Alter it as follows:

<UserControl x:Class=”System.Windows.Controls.UserControl”
    xmlns=”http://schemas.microsoft.com/client/2007″
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>

  <Grid x:Name=”layout_root” Background=”White”>
    <TextBlock x:Name=”message” FontSize=”30″ />
    <Button x:Name=”button_main”
        Height=”30″ Width=”100″
        HorizontalAlignment=”Right”
        VerticalAlignment=”Top”
        Margin=”0,10,10,0″
        Content=”Click”
        />
  </Grid>

</UserControl>

6. open the file app.rb. Alter it as follows:

require “silverlight”

class App < SilverlightApplication
  use_xaml

  def initialize
    message.text = “Welcome to Ruby and Silverlight!”
    button_main.click do |sender, args|
        button_main_click
    end
  end
  def button_main_click
      message.text = “Hello from the click handler”
  end
end

$app = App.new

The “do” in this case is wiring up a .NET delegate as the event handler for click event.

7. refresh the browser (or relaunch via Chiron per step 3 if you closed the browser).

image

There are a lot of other samples that are out there as well. Check out the ones under the sdlsdk/samples directory. Right now there’s a simple clock and a Flickr photoviewer that shows a lot of DOM and JavaScript integration.

You can also find samples at:

http://silverline.schementi.com/

If you want to play with IronRuby or IronPython you can get started playing in the DLRConsole found at http://silverlight.net/samples/sl2/dlrconsole/index.html. All the source for that is under the SDLSDK samples as well.

I’ll update the post once they put up the recording – .NET Coffee Break Show

Leave a Reply

Your email address will not be published. Required fields are marked *