silverlight 2.0 入门教程(一)

前几天由于自己的家里的电脑出了一点上的问题,重新做了一下系统,把所有的东西都重新做了一次,没有天急写这方面的文章。今天从公司里面把silverlight 2.0 的SDK下载了下来,这里我就不说这么多的话吧,还是来看看哟
首先在这里声明一点,可能没有其他的高手写得哪么的精,但是我的文章是为了给初学者一点帮助就OK了

在你自己的电脑按装VS2008,装好以后可到关方网站上下一个silverlight 2.0 SDK,这个SDK大约有50M,也不很大,
注:如果你是VS2005,你是安装不上的2.0的SDK,只有VS2008才可以,这个我自己测试过;安装这个有一点慢,要用心等,

上面的工作完了以后,我们就可以开始建一个项目了
这里可以在你的项目中会出一silverlight 这个模板,选择它,会出一个对话框子,这里可以任一选一个,都可以,主要是用来托管它,在我们的解决方案中就会出现,
这是我们不做任何的操作,只将我们的项目重新生成一下就OK了,会发现我们的工程中有多了一个文件夹,这个文件夹把所有的silverlight 用来的DLL通过了高压缩。

后下面的代码:
代码说明:
HorizontalAlihnment:是Grid排版方面,他有四个值,Stretch,right,center,left
showGridLines:显示出Grid中的网格线,默认为false
在给按钮加事件时,只要我们给按钮取上一个名字,在page.xaml.cs后台代码会自动给我们写来,
我们只是写事件下面应该做什么就OK

<UserControl x:Class="SilverlightApplication1.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="Blue" HorizontalAlignment="Left" ShowGridLines="True">
        
<Grid.RowDefinitions>
            
<RowDefinition Height="100"/>
            
<RowDefinition Height="100"/>
            
<RowDefinition Height="100"/>
        
</Grid.RowDefinitions>
        
<Grid.ColumnDefinitions>
            
<ColumnDefinition Width="100"/>
            
<ColumnDefinition Width="100"/>
            
<ColumnDefinition Width="100"/>
        
</Grid.ColumnDefinitions>
        
<Button x:Name="MyButton" Content="Push Me" Width="100" Height="50" Grid.Column="1" Grid.Row="0" Click="MyButton_Click"></Button>
        
<Button x:Name="MyButton2" Content="Button2" Width="100" Height="50" Grid.Column="0" Grid.Row="1" Click="MyButton2_Click"></Button>
        
<Button x:Name="MyButton3" Content="Button3" Width="100" Height="50" Grid.Column="2" Grid.Row="1" Click="MyButton3_Click"></Button>
        
<Button x:Name="MyButton4" Content="Button4" Width="100" Height="50" Grid.Column="1" Grid.Row="2" Click="MyButton4_Click"></Button>
        
<Button x:Name="MyButton5" Content="Button5" Width="100" Height="50" Grid.Column="2" Grid.Row="0" Click="MyButton5_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 SilverlightApplication1
{
    
public partial class Page : UserControl
%
posted @ 2008-04-18 08:49  阳光追梦  阅读(5683)  评论(1编辑  收藏  举报
/*快速评论*/ #div_digg { position: fixed; bottom: 10px; right: 15px; border: 2px solid #ECD7B1; padding: 10px; width: 140px; background-color: #fff; border-radius: 5px 5px 5px 5px !important; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); } /** 不知道为什么页面加载完成时还读不到div_digg。可能也是动态生成的。 所以这里只能用定时器 不断的读取,当读取到了再给它动态添加快捷按钮 **/ //自定义 定时器[当元素加载完成是执行回调函数] function customTimer(inpId,fn) { if ($(inpId).length) { fn(); } else { var intervalId = setInterval(function () { if ($(inpId).length) { //如果存在了 clearInterval(intervalId); // 则关闭定时器 customTimer(inpId,fn); //执行自身 } }, 100); } } //页面加载完成是执行 $(function () { customTimer("#div_digg", function () { var div_html = "
\ 关注\  | \ 顶部\  | \ 评论\
"; $("#div_digg").append(div_html); //tbCommentBody }); });