在silverlight beta 2 中已经支持了动态语言.但是在Visual Studio 和 Experssion Blend中还没有使用动态语言的模版.我们目前只可以手动建立.
编辑页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>start DLR</title> <style type="text/css"> html, body { height: 100%; overflow: auto; } body { padding: 0; margin: 0; } #silverlightControlHost { height: 100%; } </style> </head> <body> <div id="silverlightControlHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%"> <param name="source" value="app.xap" /> <param name="background" value="white" /> <param name="windowless" value="true" /> </object> <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe> </div> </body> </html>
注意意中的source参数"app.xap".我们的文件中并没有这个文件.这是由SDK中的Chiron自动生成的.你存放sl代码的文件夹也必须叫这个名字"app".其中动态代码的名字必须是app.比如"app.rb","app.xaml"
在根目录下建立app文件夹.再此目录下添加xml文件命名为app.xaml.
<UserControl xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="System.Windows.Controls.UserControl" x:Name="Page" > <TextBlock x:Name="txtMessage" TextWrapping="Wrap" Foreground="Black" Text="Hello World" > </TextBlock> </UserControl>
到了这一步就可以开始写rb的代码了.
include System::Windows include System::Windows::Controls include System::Windows::Media class SilverlightApplication def application Application.current end def self.use_xaml(options = {}) options = {:type => UserControl, :name => "app"}.merge(options) Application.current.load_root_visual(options[:type].new, "#{options[:name]}.xaml") end def root application.root_visual end def method_missing(m) root.send(m) end end class FrameworkElement def method_missing(m) find_name(m.to_s.to_clr_string) end end class App < SilverlightApplication use_xaml def initialize txtMessage.text = "Welcome to Ruby in Silverlight" end end