Experience in creating Silverlight controls in Python

Source: Internet
Author: User

What functions does the Python programming language help us implement? What are its main application scopes? Let's take a look at the implementation methods for creating a Silverlight Control Using Python, so as to get familiar with the application methods and features of this language.

  • Main functions of the Python Thread class
  • Analysis on the practical application of Python two-dimensional array
  • Correct understanding of how to use Python sys. arg
  • Python inheritance embodies object-oriented features
  • Main steps for Python to call. net framework

In fact, I have been paying attention to Silverlight for a long time, but I was disappointed with the initial version. In my opinion, Silverlight 1.0 is equivalent to VML or SVG of the enhanced version. It was four years ago) I have always hoped that Microsoft can develop a powerful web plug-in that can compete with flash. After so long, this thing will gradually become a reality.

Okay, Silverlight 2 is available. Although it is still in beta, let's get started. I made a Visual Studio 2008 Express version with Web and C # installed, and even did not support Silverlight development of 2.0. Is there any mistake that it is intended for those controls to play SL, what should I do.

This is depressing, so I had to install the full version of Visual Studio 2008, which is very big. I sorted out the hard disk space and managed to give it a bit of space, N after a long time, I finally finished the installation. After a long time, the damn plug-in couldn't be installed again. After a long time, I still couldn't do it. I was very angry. Forget it, don't do it anymore.

So I decided not to use VS2008 to create a Silverlight control in Python. I heard that Silverlight 2.0 supports dynamic languages. I used to do JavaScript. Let's change it. I came to play with Python, so I looked for an example and found it. Why? I wrote it:

Here is the XAML file app. xaml.

 
 
  1. < Canvas xmlns="http://schemas.microsoft.com/client/2007"   
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  3. x:Class="System.Windows.Controls.Canvas" x:Name="Page" 
    Width="400" Height="300">   
  4. < TextBlock x:Name="MsgText" Canvas.Top="10" Canvas.Left="10"> 
  5. < /TextBlock>   
  6. < Button x:Name="TestButton" Canvas.Top="40" Canvas.Left="10" 
    Content="Test">< /Button>   
  7. < /Canvas> 

Here is the Python file app. py

 
 
  1. from System.Windows import Application   
  2. from System.Windows.Controls import *   
  3. from System.Windows.Browser import *   
  4. class App:   
  5. def __init__(self):   
  6. self.scene = Application.Current.LoadRootVisual(Canvas(), "app.xaml")   
  7. def start(self):   
  8. self.scene.TestButton.Click += self.TestButton_Click   
  9. def TestButton_Click(self, sender, eventArgs):   
  10. self.scene.MsgText.Text = "Hello, world!"   
  11. App().start() 

There is no suspense to others. Chiron/d starts to run. http: // localhost: 2060/index.htm has an effect. A text box, a button, and click the button, the box contains a hello, world!

So I was very excited. It turned out to be so fun. It seems that it was very easy to create a Silverlight control in Python. So let's create two complicated controls. What controls are pretty handsome? I think, calendar, this is a good thing. Then I started, and I added a line.

 
 
  1. < Calendar x:Name="TestCalendar" Canvas.Top="10" Canvas.Left="10"/> 

Okay, start running. Sorry, no. I couldn't find the Calendar. I studied the document and found that it was included in System. windows. controls. extended. dll, So I copied this dll to the app directory, but it still doesn't work. What should I do? I searched it everywhere, I found that there was no article about Python calling the SL extension control, which is painful.

But I am unwilling to do so. I believe Microsoft will not be so unfriendly, so I will continue to look for help. I will add a prefix before Calendar and Calendar for namespace, but how can I define it on The XAML header, I thought about it, but I really couldn't think of it. Then I thought of Blend very cruelly. Hey, I downloaded one, installed it, created a project, and created a control, at this time, only internal controls can be used, and then I add the System referenced in the SDK directory on the project. windows. controls. extended. dll, so you can create a calendar.

This is not what I want. Switch to the XAML bar and see no. This line of code:

Xmlns: System_Windows_Controls_Extended = "clr-namespace: System. windows. controls; assembly = System. windows. controls. extended ", it turns out that it is working, so I defined it again, but it still does not work...

What's going on? I continued to work on the document and finally found that I had to write something in the Python file. I posted the complete code for creating the Silverlight control in Python, app. py

 
 
  1. import clr   
  2. clr.AddReference("System.Windows.Controls.Extended")   
  3. from System.Windows import Application   
  4. from System.Windows.Controls import *   
  5. from System.Windows.Browser import *   
  6. class App:   
  7. def __init__(self):   
  8. self.scene = Application.Current.LoadRootVisual(Canvas(), "app.xaml")   
  9. def start(self):   
  10. # TODO: replace this with your application start logic   
  11. self.scene.TestButton.Click += self.TestButton_Click   
  12. def TestButton_Click(self, sender, eventArgs):   
  13. HtmlPage.Window.Alert(self.scene.TestCalendar.SelectedDate.ToString())   
  14. App().start() 

Haha, No. The first two sentences are the key to the function. Below is app. xaml

 
 
  1. < Canvas xmlns="http://schemas.microsoft.com/client/2007"   
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:System_Windows_Controls_Extended="clr-namespace:
    System.Windows.Controls;assembly=System.Windows.Controls.Extended"   
  3. x:Class="System.Windows.Controls.Canvas" x:Name="Page" 
    Width="400" Height="300">   
  4. < System_Windows_Controls_Extended:Calendar 
    x:Name="TestCalendar" Canvas.Top="10" Canvas.Left="10"/>   
  5. < Button x:Name="TestButton" Canvas.Top="180" 
    Canvas.Left="10" Content="Test">< /Button>   
  6. < /Canvas> 

The preceding section describes how to create a Silverlight control in Python.

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.