使用动态语言来制作silverlight

 

在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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值