在silverlight beta 2 中已經支援了動态語言.但是在Visual Studio 和 Experssion Blend中還沒有使用動态語言的模版.我們目前隻可以手動建立. ok 開始吧~
準備工作:
<a href="http://www.codeplex.com/dynamicsilverlight/Release/ProjectReleases.aspx?ReleaseId=11955">Dynamic Silverlight SDK</a>
<a href="http://www.microsoft.com/silverlight/resources/installationFiles.aspx?v=2.0">Silverlight 2 Runtime</a>
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=4E03409A-77F3-413F-B108-1243C243C4FE&displaylang=en">Silverlight 2 SDK</a>
建立立一個空網站

接下來右鍵點選解決方案選擇添加新項.添加一個html頁面.命名為default.htm
編輯該頁面
<!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
</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>
這裡以ruby為例.在app目錄下添加一個text檔案.命名為app.rb
到了這一步就可以開始寫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")
def root
application.root_visual
def method_missing(m)
root.send(m)
end
class FrameworkElement
find_name(m.to_s.to_clr_string)
class App < SilverlightApplication
use_xaml
def initialize
txtMessage.text = "Welcome to Ruby in Silverlight"
App.new
為了運作起來需要在vs中設定一下.
在網站屬性頁中的啟動選項選擇"啟動外部程式",選中sdk中的"Chiron.exe".指令行參數為"/b".工作目錄設定為項目所在目錄.
按F5運作程式
浏覽器打開http://localhost:2060.在這裡你可以用目錄浏覽的方式檢視檔案.
點選default.htm
顯示了"Welcome to Ruby in Silverlight".這是由rb檔案控制的.
修改代碼.
#txtMessage.text = "Welcome to Ruby in Silverlight"
注釋掉設定文本的語句.
按F5重新整理浏覽器
顯示"Hello World".這是xaml自己描述的.
ok 介紹完畢.
<a href="http://files.cnblogs.com/nasa/silverlight/start.zip">http://files.cnblogs.com/nasa/silverlight/start.zip</a>