在silverlight 使用 IronPython

在silverlight 使用 IronPython,第1张

概述     在silverlight 中是支持IronRUBY,IronPython,Managed JScript开发的,只可惜目前我还 没找到什么特别简单易用的插件在VS上能够直接进行开发的,所以在写本文这个DEMO时,我又打 开了“记事本”,开始写IronPython代码。       从Silverlight SDK中有相应的开发文章和代码,虽然我本身通过它所提供的代码进行编译并运 行成功。      在silverlight 中是支持IronRUBY,IronPython,Managed Jscript开发的,只可惜目前我还
没找到什么特别简单易用的插件在VS上能够直接进行开发的,所以在写本文这个DEMO时,我又打
开了“记事本”,开始写IronPython代码。

      从Silverlight SDK中有相应的开发文章和代码,虽然我本身通过它所提供的代码进行编译并运
行成功。但我总想着在里面多写一些代码,以便了解一下
IronPython 。但这一写才发现了一些问题,
其中包括:

    1. 输入框不支持中文(但可以粘帖中文,但代码中写入中文显示时会出现乱码)
    2. 对有事件绑定的控件如果在XAML中声明会报错
    3. 注释如果是相应事件中唯一的代码时会报错
   
    后来在网上去找解决方案,发现【孟子E章】在这篇文篇:
   
    Silverlight 2学习教程(四):Chiron.exe:Silverlight 2打包和动态语言部署工具 
   
    也提到了相似的问题,看来不是我一个人的问题了。好在我找到了加入button的方式。
   
    好了,下面就是相应的XAML代码(app.xaml,注意里面的控件不要绑定事件,事件会在py
文件中进行绑定):
   
< 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"  WIDth ="400"  Height ="300" >
    
< GrID  x:name ="LayoutRoot"  Background ="White" >
      
< Canvas  Canvas.top ="20" >
          
< TextBlock  Canvas.top ="10"  Canvas.left ="20" > please input you name </ TextBlock >
          
< TextBox  x:name ="Userinput"  WIDth ="200"  Height ="30"  Canvas.top ="40"  Canvas.left ="20" >
          </
TextBox >
          
< TextBlock  x:name ="Msg"  Canvas.top ="90"  Canvas.left ="20"  Foreground ="Navy"  FontSize ="48"   >
          </
TextBlock >
          
< button  x:name ="Msgbutton"  Canvas.top ="130"  Canvas.left ="20"  Content ="Hello" ></ button >
      
</ Canvas >
    
</ GrID >
</ UserControl >
   
    下面就是相应的pathon代码(app.py):
   
# 名空间引用
from  System.windows  import  Application
from  System.windows.Controls  import   *
from  System.windows.browser  import   *

# 类外部事件声明
def  handler1(sender, eventArgs):
    sender.Opacity 
/=   2

class  App:
    
def   __init__ (self):
        self.scene 
=  Application.Current.LoadRootVisual(UserControl(),  " app.xaml " )

    
def  start(self):
        
#  Todo: replace this with your application start logic
        self.scene.Userinput.Text  =   " please input your name. "
        
# 在此进行类外部事件绑定
        self.scene.Userinput.MouseleftbuttonUp  +=  handler1
        
# 在此进行类内部事件绑定
        self.scene.Userinput.MouseleftbuttonUp  +=  self.handler2
        
# 在此进行button事件绑定
        self.scene.Msgbutton.Click  +=  self.Msgbutton_Click
       
    
# 类内部事件声明
     def  handler2(self, sender, eventArgs):
        sender.FontSize 
=  sender.FontSize  # 此处如果注释代码会报错,让我很晕

   
    
def  Msgbutton_Click(self, eventArgs):
        @[email protected](
" hello,  "   +  self.scene.Userinput.Text  +   " ! " # 显示输入信息

App().start()

      看来代码果然比我们所使用的C#简单很多,代码更少了将近一半。
   
      下载就运行Chiron.exe来打包运行xap文件,在CMD命令行运行下面命令行:
   
      c:/py>"C:/Program files/Microsoft SDKs/Silverlight/v2.0/Tools/Chiron/Chiron.exe" /w


     
   
    而其运行结果如下:

   


   
    好了,今天代码就到这里了。
   
    源码下载,请点击这里:)
总结

以上是内存溢出为你收集整理的在silverlight 使用 IronPython全部内容,希望文章能够帮你解决在silverlight 使用 IronPython所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1055036.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存