前言: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 2.0 (1) 开发环境准备

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

乱弹琴 Silverlight 2.0 (1) 开发环境准备

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

乱弹琴 Silverlight 2.0 (1) 开发环境准备

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

乱弹琴 Silverlight 2.0 (1) 开发环境准备

可以看到,很多功能都可用,如:System.Net/System.Text/System.XML/System.IO等等非常多的类都被支持。你可以用System.IO命名空间的FileInfo类访问文件试试,呵呵,出于安全考虑,这是不被允许的乱弹琴 Silverlight 2.0 (1) 开发环境准备

代码: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>

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();
        }
    }
}

似曾相识的感觉,就像搭起了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!";
}

F5运行:
按钮点击前:
乱弹琴 Silverlight 2.0 (1) 开发环境准备
按钮点击后:
乱弹琴 Silverlight 2.0 (1) 开发环境准备
编译运行后,FirstSilverlight_Web多了个ClientBin文件夹,里面有个FirstSilverlight.xap文件,用十六进制编辑器打开可看到开头字母为:PK,对了,就是个zip格式的压缩文件。这是运行是发送到客户端由客户端执行的文件。用winrar打开可看到:
乱弹琴 Silverlight 2.0 (1) 开发环境准备

第一篇终于结束了,看起来不太复杂,后面继续。

相关文章:

  • 2022-02-27
  • 2022-01-19
  • 2021-12-29
  • 2021-10-05
  • 2021-10-10
  • 2021-07-22
  • 2021-08-22
  • 2021-10-26
猜你喜欢
  • 2021-11-20
  • 2021-11-16
  • 2022-12-23
  • 2021-08-14
  • 2021-11-10
  • 2021-08-03
  • 2021-12-02
相关资源
相似解决方案