使用动态语言来制作silverlight

简介: 在silverlight beta 2 中已经支持了动态语言.但是在Visual Studio 和 Experssion Blend中还没有使用动态语言的模版.我们目前只可以手动建立. ok  开始吧~ 准备工作: Dynamic Silverlight SDK Silverlight 2 ...
在silverlight beta 2 中已经支持了动态语言.但是在Visual Studio 和 Experssion Blend中还没有使用动态语言的模版.我们目前只可以手动建立. ok  开始吧~
准备工作:
Dynamic Silverlight SDK
Silverlight 2 Runtime
Silverlight 2 SDK

新建立一个空网站

接下来右键点击解决方案选择添加新项.添加一个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
        
{
            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 >

这种写法的原因你可以看看我的这篇文章:" 有趣 不用js也能创建silverlight"

注意意中的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 " )
  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

App
. new


为了运行起来需要在vs中设置一下.
在网站属性页中的启动选项选择"启动外部程序",选中sdk中的"Chiron.exe".命令行参数为"/b".工作目录设置为项目所在目录.

按F5运行程序

浏览器打开http://localhost:2060.在这里你可以用目录浏览的方式查看文件.
点击default.htm

显示了"Welcome to Ruby in Silverlight".这是由rb文件控制的.
修改代码.
  def initialize
    
# txtMessage.text = "Welcome to Ruby in Silverlight"
  end

注释掉设置文本的语句.
按F5刷新浏览器

显示"Hello World".这是xaml自己描述的.

ok  介绍完毕.

http://files.cnblogs.com/nasa/silverlight/start.zip


相关文章
|
17天前
|
存储 弹性计算 人工智能
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
2025年9月24日,阿里云弹性计算团队多位产品、技术专家及服务器团队技术专家共同在【2025云栖大会】现场带来了《通用计算产品发布与行业实践》的专场论坛,本论坛聚焦弹性计算多款通用算力产品发布。同时,ECS云服务器安全能力、资源售卖模式、计算AI助手等用户体验关键环节也宣布升级,让用云更简单、更智能。海尔三翼鸟云服务负责人刘建锋先生作为特邀嘉宾,莅临现场分享了关于阿里云ECS g9i推动AIoT平台的场景落地实践。
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
|
8天前
|
云安全 人工智能 安全
Dify平台集成阿里云AI安全护栏,构建AI Runtime安全防线
阿里云 AI 安全护栏加入Dify平台,打造可信赖的 AI
|
11天前
|
人工智能 运维 Java
Spring AI Alibaba Admin 开源!以数据为中心的 Agent 开发平台
Spring AI Alibaba Admin 正式发布!一站式实现 Prompt 管理、动态热更新、评测集构建、自动化评估与全链路可观测,助力企业高效构建可信赖的 AI Agent 应用。开源共建,现已上线!
1035 35
|
11天前
|
机器学习/深度学习 人工智能 搜索推荐
万字长文深度解析最新Deep Research技术:前沿架构、核心技术与未来展望
近期发生了什么自 2025 年 2 月 OpenAI 正式发布Deep Research以来,深度研究/深度搜索(Deep Research / Deep Search)正在成为信息检索与知识工作的全新范式:系统以多步推理驱动大规模联网检索、跨源证据。
801 55
|
9天前
|
文字识别 测试技术 开发者
Qwen3-VL新成员 2B、32B来啦!更适合开发者体质
Qwen3-VL家族重磅推出2B与32B双版本,轻量高效与超强推理兼备,一模型通吃多模态与纯文本任务!
690 11
下一篇
开通oss服务