Silverlight is a new way to create dynamic, compelling RIAs (Rich Internet application). This teaches you to create a simple Silverlight application.
1. Open vs, new project, select Silverlight Application template.
2. Name Mysimplesilverlightapplication, click OK.
3. In the pop-up dialog box, clear the "host Silverlight applications in new site" check box, click OK.
4. Your interface should be like this.
5. Drag four controls (2 labels, a text box, and a button).
6. The X:name property represents the name (or ID) of the Silverlight control. Make sure that the final code is like this:
<usercontrol x:class= "Mysimplesilverlightapplication.mainpage" xmlns= "http://schemas.microsoft.com/winfx/2006 /xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:d=" http://schemas.microsoft.com /expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "D" :D esignheight= "204" d:designwidth= "xmlns:datainput=" clr-namespace:system.windows.controls;assembly= System.Windows.Controls.Data.Input "> <grid x:name=" layoutroot "background=" white "height=" 186 "> < Datainput:label content= "My A-Silverlight App" height= "horizontalalignment=" left "margin=" 42,32,0,0 "Name=" Lbltitle "verticalalignment=" Top "width=" fontweight= "Bold"/> <button "click=" "Btnname_click" Greeting "height=" horizontalalignment= "left" margin= "42,115,0,0" name= "Btnname" verticalalignment= "Top" Width= " "/> <textbox height=" horizontalalignment= "left" margin= "104,72,0,0" name= "Txtbxname" VeRticalalignment= "Top" width= "163"/> <datainput:label content= "Name:" height= "horizontalalignment=" Margin= "42,72,0,0" name= "Lblname" verticalalignment= "Top" width= "a"/> </Grid> </UserControl>
The interface is like this:
7. Right-click MainPage.xaml to view the code.
8. Add code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Net;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Animation;
Using System.Windows.Shapes;
Namespace Mysimplesilverlightapplication
{public
partial class Mainpage:usercontrol
{
public MainPage ()
{
InitializeComponent ();
}
private void Btnname_click (object sender,
RoutedEventArgs e)
{
string mynameprefix = "Length of Name:"; c23/>string myname = Txtbxname.text;
int mynamelength = 0;
Mynamelength = myname.length;
MessageBox.Show (Mynameprefix +
mynamelength.tostring ());
Btnname.content = "Goodbye";}}
9. F5 Test.
Add the Silverlight Web Part on the SharePoint site.
Author: csdn Blog Zhang Shihui
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/Silverlight/