silverlight(一.安装和新建项目)
时间:2010-09-28 来源:Simcoder
1.下载安装silverlight:Microsoft® Silverlight™ 3 Tools (安装之前需要升级VS2008到SP1)
2.和多数人一样我的程序新建好运行调试报错,提示“未安装silverlight托管调试包”,后来我使用VS2010新建的时候提示安装silverlight更高版本Silverlight_Developer.exe,我安装好后就OK了,然后运行VS2008的项目也没有报错了,整理一下我自己的安装顺序: VS2008(后来又安装了VS2010),framework3.5-SP1, VS2008—SP1 ,silverlight3,Silverlight_Developer.exe。
3.新建项目 新建一个silverlight导航应用程序
然后找到Views中的Home.xaml文件 F5调试运行
然后添加silverlight控件:button 和 textbox
双击按钮书写代码
Home.xaml页面代码:

<Grid x:Name="LayoutRoot">
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
<StackPanel x:Name="ContentStackPanel">
<TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" Text="主页"/>
<Button Content="点我" Height="42" Name="button1" Width="119" Click="button1_Click" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}" Text="主页内容"/>
<TextBox Height="23" Name="textBox1" Width="120" />
</StackPanel>
</ScrollViewer>
</Grid>
</navigation:Page>
Home.xaml.cs

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.Navigation;
using System.Windows.Shapes;
namespace SilverlightApplication3
{
public partial class Home : Page
{
public Home()
{
InitializeComponent();
}
// 当用户导航到此页面时执行。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
HeaderText.Text = "我的第一个silverlight应用程序!";
textBox1.Text = DateTime.Now.ToString();
}
}
}
相关阅读 更多 +