Use IronPython and other dynamic languages in Silverlight 2 beta1

Source: Internet
Author: User

Currently, Silverlight Tools Beta 1 for Visual Studio 2008 includes three Dynamic Language Runtime libraries: IronPython, IronRuby, and Managed JScript.

However, VS2008 has not yet completed the templates for these three dynamic languages. Therefore, we cannot create a dynamic language Silverlight 2 project (or even VB). The default value is C ); however, the Silverlight 2 SDK provides a tool to help us generate the deployed xap file-The Chiron tool, which is in the directory: C: \ Program Files \ Microsoft SDKs \ Silverlight \ v2.0 \ Tools \ Chiron.

In addition, a Dynamic Silverlight Sample project is provided on CodePlex to guide us to use Dynamic languages in Silverlight 2. However, this project is still for Silverlight 1.1.

The following is an example of IronPython ):

  • Create a directory, such as IPSL2, and create two subdirectories: app (including dynamic language code files and XAML file files) and assets (including resource files and slices ); create a sub-directory js in assets (this directory can not be used, in 1.1 is used to save silverlight. but now you can save other js files ).
  • Create an IronPython code file in the app Directory: app. py, the Code is as follows (here, I am using XamlReader. load loads the xaml string directly. Originally, I wanted to use Application. current. the LoadRootVisual method calls the app. xaml loading, but it has never been successful. Do you know how to get it ?) :

From System. Windows import Application
From System. Windows. Markup import XamlReader

Application. Current. RootVisual = XamlReader. Load ("""
<Canvas xmlns = "http://schemas.microsoft.com/client/2007"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">

<TextBlock x: Name = "message" FontSize = "30"/>

</Canvas> """)

Application. Current. RootVisual. message. Text = "Welcome to Silverlight and IronPython! "

  • Create a xaml code file in the app Directory: app. xaml (in my example, do not use this file, but use the LoadRootVisual method as needed). The Code is as follows:

<Canvas xmlns = "http://schemas.microsoft.com/client/2007"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">

<TextBlock x: Name = "message" FontSize = "30"/>

</Canvas>

  • In the root directory, in this example, ipsl2directory, create an index.html file to browse the page. The code in the body is as follows (to explain why I want to use images here, this is because after I paste the code in Windows Live Writer, A Silverlight control is displayed in the control. It is !) :

  • Now we are using the release on tool to run the Dynamic Language Silverlight 2 application.
  • First, add the directory where login on is located to PATH.
  • Start the command line, enter the IPSL2 directory, run login on/B to start a Web Server, and open a browser at the same time
  • Click the index.html file in the browser and you will see that the Silverlight over IronPython application is running, for example:

In addition, for IronRuby users, refer to John Lam's article (note: the connection I provided below is accessed through a Web proxy and cannot be accessed directly ):

John Lam on Software Dynamic Silverlight Part 1 Hello, World!

John Lam on Software Dynamic Silverlight Part 2 Managed JScript and flickr

The entire sample code is downloaded here: http://www.91files.com /? GXW6W7RN1L2N1N358LJC

Update!
For reminders that app. py and app. xaml can be thought of, you can use the following code (in fact, I tried the code last night, and the result was not successful, it was just dizzy !) :
App. py:
================
From System. Windows import Application
From System. Windows. Controls import UserControl

Application. Current. LoadRootVisual (UserControl (), 'app. xaml ')

Application. Current. RootVisual. message. Text = "Welcome to Silverlight and IronPython! "
================
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 = "message" FontSize = "30"/>

</UserControl>
================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.