教你使用Visual Studio 2010建立簡單的Silverlight應用程式

來源:互聯網
上載者:User

Silverlight是建立動態引人的RIAs(Rich Internet Application)的新方法。這裡教你建立簡單的Silverlight應用程式。

1. 開啟VS,建立項目,選擇Silverlight應用程式模板。

2. 命名mySimpleSilverlightApplication,點擊確定。

3. 在彈出的對話方塊中,清除“在新網站中承載Silverlight應用程式”複選框,點擊確定。

4. 你的介面應該是這樣的。

5. 拖四個控制項(2個標籤、1個文字框和1個按鈕)。

6. x:Name屬性代表了Silverlight控制項的名稱(或ID)。確保最後的代碼是這樣的:

<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:DesignHeight="204" d:DesignWidth="400" 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 First Silverlight App" Height="21"HorizontalAlignment="Left" Margin="42,32,0,0" Name="lblTitle"VerticalAlignment="Top" Width="225" FontWeight="Bold"  /><Button Click="btnName_Click" Content="Greeting"Height="23" HorizontalAlignment="Left"Margin="42,115,0,0" Name="btnName" VerticalAlignment="Top"Width="75"  /><TextBox Height="23" HorizontalAlignment="Left"Margin="104,72,0,0" Name="txtbxName" VerticalAlignment="Top"Width="163"  /><dataInput:Label Content="Name:" Height="21"HorizontalAlignment="Left" Margin="42,72,0,0" Name="lblName"VerticalAlignment="Top" Width="56"  /></Grid></UserControl>

介面是這樣的:

7. 右擊MainPage.xaml查看代碼。

8. 添加代碼如下:

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: ";string myName = txtbxName.Text;int myNameLength = 0;myNameLength = myName.Length;MessageBox.Show(myNamePrefix +myNameLength.ToString());btnName.Content = "Goodbye";}}}

9. F5測試。

在SharePoint網站上添加Silverlight Web組件。

作者:csdn部落格 張世輝

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/Silverlight/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.