在Silverlight Toolkit 3.0中提供了强大灵活的数据分页控件:DataPager。并且其还有多种显示样式 (displayMode) 供使用。终于可以不用再自己费神巴力去实现分页功能了,下面是其演示效果:
接着介绍一下其使用方法。
首先,我们要新建一个Silverlight应用,并添加对下面DLL的引用:
System.windows.Data(其提供了PagedCollectionVIEw类用于实现分页绑定)System.windows.Controls.Data(分页器控件DataPager所在DLL)
XAML文件头部名空间声明:
然后我们要在当前XAML中放置一个DataGrID用于显示列表数据,声明如下:
为了演示不同显示样式(displayMode)的效果,下面根据其样式分别加以声明:
HorizontalAlignment ="left" Source =" {Binding} " NumericbuttonCount ="3" autoEllipsis ="True" />
< data:DataPager x:name ="FirstLastPrevIoUsNext" GrID.Column ="0" GrID.Row ="3" displayMode ="FirstLastPrevIoUsNext"
margin ="0,4" HorizontalAlignment ="left" Source =" {Binding} " NumericbuttonCount ="3" autoEllipsis ="True" />
< data:DataPager x:name ="FirstLastPrevIoUsNextNumeric" GrID.Column ="0" GrID.Row ="4" displayMode ="FirstLastPrevIoUsNextNumeric"
margin ="0,4" HorizontalAlignment ="left" Source =" {Binding} " NumericbuttonCount ="4" autoEllipsis ="True" />
< data:DataPager x:name ="Numeric" GrID.Column ="0" GrID.Row ="5" displayMode ="Numeric" HorizontalAlignment ="left"
margin ="0,4" Source =" {Binding} " NumericbuttonCount ="6" autoEllipsis ="False" />
< data:DataPager x:name ="PrevIoUsNext" GrID.Column ="0" GrID.Row ="6" displayMode ="PrevIoUsNext" margin ="0,4"
HorizontalAlignment ="left" Source =" {Binding} " NumericbuttonCount ="3" autoEllipsis ="False" />
< data:DataPager x:name ="PrevIoUsNextNumeric" GrID.Column ="0" GrID.Row ="7" displayMode ="PrevIoUsNextNumeric" margin ="0,4"
HorizontalAlignment ="left" Source =" {Binding} " NumericbuttonCount ="4" autoEllipsis ="False" />
好了,为了便于演示,我“硬编码”了一个数据对象集合如下:
{
List < EmployeeInfo > employeeList = new List < EmployeeInfo > ();
employeeList.Add( new EmployeeInfo { EmployeeID = 1 , Employeename = " 大林 " , Salary = 1000 , City = " 合肥 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 2 , Employeename = " 小林 " , City = " 合肥 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 3 , Employeename = " 张三 " , City = " 合肥 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 4 , Employeename = " 李四 " , Salary = 1500 , City = " 天津 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 5 , Employeename = " 王五 " , Salary = 2000 , City = " 上海 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 6 , Employeename = " 赵六 " , Salary = - 800 , City = " 北京 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 7 , Employeename = " 尤七 " , Salary = 2100 , City = " 武汉 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 8 , Employeename = " 马八 " , Salary = 2300 , City = " 海口 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 9 , Employeename = " 许九 " , City = " 海口 " });
employeeList.Add( new EmployeeInfo { EmployeeID = 10 , Employeename = " 代十 " , City = " 海口 " });
return employeeList;
}
public class EmployeeInfo
{
public int EmployeeID { set ; get ; }
public string Employeename { set ; get ; }
public int Salary { set ; get ; }
public int [] Cost { get ; set ; }
public string City { set ; get ; }
}
接下来就是如何实现分页,以及相关控件的数据绑定了,代码位于MyDataPager.xaml.cs(详见注释):
public MyDataPager()
{
InitializeComponent();
PagedCollectionVIEw pcv = new PagedCollectionVIEw(GetEmployeeList());
pcv.PageSize = 3 ; // 一页显示三条记录
// 列表控件数据源绑定
MyDataGrID.DataContext = pcv;
MyListBox.DataContext = pcv;
// 分页控件数据源绑定
FirstLastNumeric.DataContext = pcv;
FirstLastPrevIoUsNext.DataContext = pcv;
FirstLastPrevIoUsNextNumeric.DataContext = pcv;
Numeric.DataContext = pcv;
PrevIoUsNext.DataContext = pcv;
PrevIoUsNextNumeric.DataContext = pcv;
}
是不是很好用,呵呵。当然该控件还提供了NumericbuttonCount属性用于控制页码的数量,这在上面的XAML控件声明时已使用,大家可以修改测试一下效果。
好的,今天的内容就先到这里了。
源码下载:http://files.cnblogs.com/daizhj/Silverlight_ToolKit3.rar
原文链接:http://www.cnblogs.com/daizhj/archive/2009/07/23/1529331.html
作者: daizhj,代震军
Tags: silverlight,DataPager,分页
网址: http://daizhj.cnblogs.com/
总结以上是内存溢出为你收集整理的使用Silverlight Toolkit的数据分页控件---DataPager全部内容,希望文章能够帮你解决使用Silverlight Toolkit的数据分页控件---DataPager所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)