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.
- < Canvas xmlns="http://schemas.microsoft.com/client/2007"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- x:Class="System.Windows.Controls.Canvas" x:Name="Page"
Width="400" Height="300">
- < TextBlock x:Name="MsgText" Canvas.Top="10" Canvas.Left="10">
- < /TextBlock>
- < Button x:Name="TestButton" Canvas.Top="40" Canvas.Left="10"
Content="Test">< /Button>
- < /Canvas>
Here is the Python file app. py
- from System.Windows import Application
- from System.Windows.Controls import *
- from System.Windows.Browser import *
- class App:
- def __init__(self):
- self.scene = Application.Current.LoadRootVisual(Canvas(), "app.xaml")
- def start(self):
- self.scene.TestButton.Click += self.TestButton_Click
- def TestButton_Click(self, sender, eventArgs):
- self.scene.MsgText.Text = "Hello, world!"
- 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.
- < 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
- import clr
- clr.AddReference("System.Windows.Controls.Extended")
- from System.Windows import Application
- from System.Windows.Controls import *
- from System.Windows.Browser import *
- class App:
- def __init__(self):
- self.scene = Application.Current.LoadRootVisual(Canvas(), "app.xaml")
- def start(self):
- # TODO: replace this with your application start logic
- self.scene.TestButton.Click += self.TestButton_Click
- def TestButton_Click(self, sender, eventArgs):
- HtmlPage.Window.Alert(self.scene.TestCalendar.SelectedDate.ToString())
- App().start()
Haha, No. The first two sentences are the key to the function. Below is app. xaml
- < Canvas xmlns="http://schemas.microsoft.com/client/2007"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System_Windows_Controls_Extended="clr-namespace:
System.Windows.Controls;assembly=System.Windows.Controls.Extended"
- x:Class="System.Windows.Controls.Canvas" x:Name="Page"
Width="400" Height="300">
- < System_Windows_Controls_Extended:Calendar
x:Name="TestCalendar" Canvas.Top="10" Canvas.Left="10"/>
- < Button x:Name="TestButton" Canvas.Top="180"
Canvas.Left="10" Content="Test">< /Button>
- < /Canvas>
The preceding section describes how to create a Silverlight control in Python.