前言:Silverlight 2.0 Beta1 已经发布,加入了许多激动人心的新特性:WPF UI 框架、丰富的控件、丰富的网络支持、丰富的基础类库支持等。这是本人的学习笔记,写的比较乱,因此定名为乱弹琴 Silverlight 2.0 系列文章。
开发环境:
1. Visual Studio 2008
2. Microsoft Silverlight Tools Beta 1 for Visual Studio 2008(包括VS2008开发插件、Runtime、SDK)
概貌:
新建一个Project,选择 "Silverlight Applicateion",输入名称,确定。

弹出以下对话框,建立 silverlight 运行依附的网站。

确定后,VS2008 的Solution Explorer出现两个项目。

"FirstSilverlight"项目添加引用,可看到支持的程序集:

可以看到,很多功能都可用,如:System.Net/System.Text/System.XML/System.IO等等非常多的类都被支持。你可以用System.IO命名空间的FileInfo类访问文件试试,呵呵,出于安全考虑,这是不被允许的
。
代码:Page.xaml
Page.xaml.cs
似曾相识的感觉,就像搭起了webform和winform开发鸿沟的桥梁。
由于是Beta1,工具箱的控件很不完善,不支持拖放,那就手写吧。
惯例:Hello World!
在<Grid>之间插入如下代码:
处理Click事件的方法为:
F5运行:
按钮点击前:

按钮点击后:

编译运行后,FirstSilverlight_Web多了个ClientBin文件夹,里面有个FirstSilverlight.xap文件,用十六进制编辑器打开可看到开头字母为:PK,对了,就是个zip格式的压缩文件。这是运行是发送到客户端由客户端执行的文件。用winrar打开可看到:

第一篇终于结束了,看起来不太复杂,后面继续。
开发环境:
1. Visual Studio 2008
2. Microsoft Silverlight Tools Beta 1 for Visual Studio 2008(包括VS2008开发插件、Runtime、SDK)
概貌:
新建一个Project,选择 "Silverlight Applicateion",输入名称,确定。

弹出以下对话框,建立 silverlight 运行依附的网站。

确定后,VS2008 的Solution Explorer出现两个项目。

"FirstSilverlight"项目添加引用,可看到支持的程序集:

可以看到,很多功能都可用,如:System.Net/System.Text/System.XML/System.IO等等非常多的类都被支持。你可以用System.IO命名空间的FileInfo类访问文件试试,呵呵,出于安全考虑,这是不被允许的
。代码:Page.xaml
<UserControl x:Class="FirstSilverlight.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</UserControl>
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</UserControl>
Page.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
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 FirstSilverlight
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
}
}
using System.Collections.Generic;
using System.Linq;
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 FirstSilverlight
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
}
}
似曾相识的感觉,就像搭起了webform和winform开发鸿沟的桥梁。
由于是Beta1,工具箱的控件很不完善,不支持拖放,那就手写吧。
惯例:Hello World!
在<Grid>之间插入如下代码:
<Button x:Name="btnHelloWorld" Width="160" Height="60" Foreground="Red" Background="Blue" Content="Hello World!" Click="btnHelloWorld_Click"></Button>
处理Click事件的方法为:
private void btnHelloWorld_Click(object sender, RoutedEventArgs e)
{
btnHelloWorld.Content = "Hello World Again!";
}
{
btnHelloWorld.Content = "Hello World Again!";
}
F5运行:
按钮点击前:

按钮点击后:

编译运行后,FirstSilverlight_Web多了个ClientBin文件夹,里面有个FirstSilverlight.xap文件,用十六进制编辑器打开可看到开头字母为:PK,对了,就是个zip格式的压缩文件。这是运行是发送到客户端由客户端执行的文件。用winrar打开可看到:

第一篇终于结束了,看起来不太复杂,后面继续。
浙公网安备 33010602011771号