首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>开发工具>图解vs2008 silverlight做的helloworld小实例
图解vs2008 silverlight做的helloworld小实例
来源: 发布时间:2008-04-20 发布人: 浏览: 人次   字体: [ ]  

Silverlight2 + VS2008支持C#的SilverLightHelloworld教程,今天装好Silverlight后,第一个程序就是写个helloworld,这里贡献给Silverlight的初学者,希望对你有用! 

这里我认为您已经装好VS2008和Siverlight2 beta1,:)

下面就开始我们的helloworld之旅吧!hoho

1、打开vs2008-〉创建Siverlight Application项目

2、输入SilverLightHelloWorld->OK我们将看到:

3、选择第二项Generate an ....   ->OK,我们将看到下图创建好的工程:

4、我们试着编译以下F7:

编译通过没有问题,哈哈

我们将看到page.xaml代码: 

<UserControl x:Class="SilverlightHelloWorld.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>

 5、我们需要更改其xaml代码,更改Grid的背景色并添加一个Button,如下代码: 

<UserControl x:Class="SilverlightHelloWorld.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="Red">
    
<Button Content="HelloWorld" Width="100" Height="20">
    
</Button>
    
</Grid>
</UserControl>

背景改成了红色,添加了HelloWorld按钮,效果如下图:

6、我们再给HelloWorld加个Click事件,代码入下: 

<UserControl x:Class="SilverlightHelloWorld.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="Red">
    
<Button Content="HelloWorld" Width="100" Height="20" Click="Button_Click">
    
</Button>
    
</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 SilverlightHelloWorld
{
    
public partial class Page : UserControl
    
{
        
public Page()
        
{
            InitializeComponent();
        }


        
private void Button_Click(object sender, RoutedEventArgs e)
        
{
            
//这里添加代码
      SolidColorBrush brush = (SolidColorBrush)this.LayoutRoot.Background;
            
if (brush.Color == Colors.Red)
            
{
                
this.LayoutRoot.Background = new SolidColorBrush(Colors.Blue);
            }

        }

    }

}

代码逻辑很简单,每点击一次按钮会更改一次背景色。

F5运行看看效果:

点击后的效果:


相 关 文 章   发布商链接
·如何在ASP.NET或Winform(C#)开发代码...
·vs2005sp1补丁安装心得
·实例讲解VS2005的复制网站功能
·vs2005脚本注册过时问题解决方法
·VS2005无法调试javascript脚本问题的...
·图解VS2005制作Web打包安装程序,包括...
·vss源码管理工具损坏提示文件夹打不...
·vs2005实现将自己的代码自动添加版权...
·几个在VS.NET中常见的错误及其解决方...
·在VS窗体设计器中如何使用泛型的控件
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·详解SourceOffsite的安装配置
·图解VS2005制作Web打包安装程
·VS2005无法调试javascript脚...
·vs2005脚本注册过时问题解决...
·实例讲解VS2005的复制网站功...
·vs2005sp1补丁安装心得
·如何在ASP.NET或Winform(C#)...
·nant是什么及其nant使用入门
·图解在VS2005利用NUnit进行测
·BugFree在Windows Server 200...
·装VS2003遇到的问题:此计算...
·IIS常见配置问题列表
·去掉VS.NET项目中的VSS代码控
·解决VISTA下安装VS 2005需要...
·如何解决不能在Web启动调试
热 门 文 章
·图解VS2005制作Web打包安装程...
·VS.NET2005安装部署之实战图...
·图解在VS2005利用NUnit进行测...
·BugFree在Windows Server 200...
·nant是什么及其nant使用入门
·解决VISTA下安装VS 2005需要...
·如何在ASP.NET或Winform(C#)...
·实例讲解VS2005的复制网站功...
·VS2005无法调试javascript脚...
·装VS2003遇到的问题:此计算...
·Visual Studio2005解决发布程...
·vs2005sp1补丁安装心得
·vs2005实现将自己的代码自动...
·IIS常见配置问题列表
·如何解决不能在Web启动调试
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .