(1)构建一个简单的SilverLight程序

SilverLight是微软的一个产品,和Wpf是同根同生,如果有人说wpf和silverlight是一个东西,抱歉,我表示质疑
我们开始来构建一个简单的silverlight程序

首先新建一个项目

 

选择Silverlight 应用程序,点击确定,会弹出一个这样的选择框

我是选择的第一个选项 就是 Asp.net web 应用程序项目

然后确定

出现界面

 

<UserControl x:Class="demo.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="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Button Height="40" Width="160" x:Name="fishButton" Content="click" Click="fishButton_Click" Background="Beige"></Button>
    </Grid>
</UserControl>

这是xaml代码,

        private void fishButton_Click(object sender, RoutedEventArgs e)
        {
            fishButton.Content = "hello world";
            fishButton.Foreground =new SolidColorBrush( Colors.Green);
        }

这是事件代码,只是一个demo,没有刻意的去什么mvvm 写vm页面

编译demo

会在这里出现一个

demo.xap

这个就是生成的文件,编译运行demo.Web,ok,恭喜你完成了第一个demo,

笔者vs2010环境,silverlight3.0运行

posted @ 2012-06-18 14:49  爱喝可乐  阅读(224)  评论(2编辑  收藏  举报