SilverLight学习笔记--实际应用(一)(1):手把手建立一个Silverlight应用程序之开始篇
在本系列文章中,我们将手把手建立一个Silverlight应用程序,在此程序中实现数据的展示,数据的添加,删除和修改以及数据的校验等常见操作。希望通过本系列文章的演示,大家一起熟悉在Silverlight工程实际应用中的此类常见问题的处理,并举一反三。
在第一篇开始篇中,我们需要完成的工作非常简单,就是定义一个数据源,并把它绑定到我们用户端进行展示。
效果如下图:

下面开始我们的工作:
1、新建一个Silverlight应用程序,命名为:SLApplicationExample。
2、新添加两个类,分别命名为 Person和People。
Person类的定义代码如下:
Code
People类的定义代码如下:
Code
3、用户界面设计,Page.xaml代码如下:
至此,应用程序如下图:

4、后台代码取数据并完成数据绑定,Page.xaml.cs代码如下:
前往:Silverlight学习笔记清单
本文程序在Silverlight2.0和VS2008环境中调试通过。本文参照了部分网络资料,希望能够抛砖引玉,大家共同学习。
(转载本文请注明出处)
在第一篇开始篇中,我们需要完成的工作非常简单,就是定义一个数据源,并把它绑定到我们用户端进行展示。
效果如下图:

下面开始我们的工作:
1、新建一个Silverlight应用程序,命名为:SLApplicationExample。
2、新添加两个类,分别命名为 Person和People。
Person类的定义代码如下:


<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SLApplicationExample.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<data:DataGrid x:Name="dgPeople" />
</Grid>
</UserControl>
此用户界面非常简单,就是加入了一个DataGrid控件,我们将在会把我们定义的People类数据源绑定到此控件中进行展示。xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<data:DataGrid x:Name="dgPeople" />
</Grid>
</UserControl>
至此,应用程序如下图:

4、后台代码取数据并完成数据绑定,Page.xaml.cs代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
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 SLApplicationExample
{
public partial class Page : UserControl
{
People mypeople;
public Page()
{
InitializeComponent();
Loaded+=new RoutedEventHandler(Page_Loaded);
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
mypeople = People.GetTestData();
this.dgPeople.ItemsSource = mypeople;
}
}
}
生成项目后运行程序即可看到我们前面展示的效果图。using System.Collections.Generic;
using System.Linq;
using System.Net;
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 SLApplicationExample
{
public partial class Page : UserControl
{
People mypeople;
public Page()
{
InitializeComponent();
Loaded+=new RoutedEventHandler(Page_Loaded);
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
mypeople = People.GetTestData();
this.dgPeople.ItemsSource = mypeople;
}
}
}
前往:Silverlight学习笔记清单
本文程序在Silverlight2.0和VS2008环境中调试通过。本文参照了部分网络资料,希望能够抛砖引玉,大家共同学习。
(转载本文请注明出处)