
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 name ="DataGrID1" autoGenerateColumns ="True" > </ data:DataGrID >
</ GrID >
</ UserControl > XMAL代码依然简单,仅仅是一个DataGrID控件,而且使用了自动产生列的方式来构建表格结构。 public class Student
{
public string name { get; set; }
public string No { get; set; }
}
public partial class DataGrID : UserControl
{
public DataGrID()
{
InitializeComponent();
List<Student> List = new List<Student>();
Student stu = new Student();
stu.No = "0001";
stu.name = "Jerry";
List.Add(stu);
stu = new Student();
stu.No = "0002";
stu.name = "Tom";
List.Add(stu);
DataGrID1.ItemsSource = List;
}
} C#代码就稍微多了一点,因为要构建数据源。Silverlight中无法使用Datatable?所以我们构建了一个List列表来表示数据,Student类表示数据结构。表格的ItemsSource 就是数据绑定接口。 效果如下: 你可能更想使用自定义列,DataGrID也可以定制模板,很好,很强大。 < UserControl xmlns:data ="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data" x:Class ="_51CTO.lesson02.DataGrID2"
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 name ="DataGrID1" autoGenerateColumns ="True" >
< data:DataGrID.Columns >
< data:DataGrIDTextColumn header ="学号" WIDth ="100" Binding ="{Binding No}" />
< data:DataGrIDTextColumn header ="姓名" WIDth ="200" Binding ="{Binding name}" />
< data:DataGrIDTemplateColumn header =" *** 作" WIDth ="100" >
< data:DataGrIDTemplateColumn.CellTemplate >
< DataTemplate >
< button Content ="删除" > </ button >
</ DataTemplate >
</ data:DataGrIDTemplateColumn.CellTemplate >
</ data:DataGrIDTemplateColumn >
</ data:DataGrID.Columns >
</ data:DataGrID >
</ GrID >
</ UserControl > 数据绑定部分是一样的。这里没有实现删除功能,只是个装饰。效果如下: 关于DataGrID的更多内容,读者可以去摩尔森博客上看。这个控件和其它Silverlight控件一样,都在继续完善。 总结
以上是内存溢出为你收集整理的《SilverLight2快速入门》之基本控件DataGrid全部内容,希望文章能够帮你解决《SilverLight2快速入门》之基本控件DataGrid所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)