Ruby Tuesday #22 : First steps with IronRuby and Silverlight
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" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid x:Name="layout_root" Background="White"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="100"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <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" /> </Grid> </UserControl>
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!"
rubyButton.click do |sender, e|
message.text = "Hello World!"
end
end
Reload your app, click the button and whoop with delight. Worth looking at index.html in an editor – the documentation will prove helpful.
Nice blog…