博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【WPF】ListView自定义分页
阅读量:4501 次
发布时间:2019-06-08

本文共 4665 字,大约阅读时间需要 15 分钟。

XAML:

1   
2
3
4
5
6
7
8
9
10
12
14
16
17
18
19
20 21
22
23
24
25
26
28
29
30
31
32
33
34
35
36
37
38 39
40
41
42 43
44
45
46 47
48
49

后台代码:

  Models:

public class Pages    {        public string Name { get; set; }        public int PageSize { get; set; }    } public class User    {        public string Name { get; set; }        public int Age { get; set; }        public string Address { get; set; }    }

ViewMode:

class PageDataManager:INotifyPropertyChanged    {        private int number;        public int Number        {            get { return number; }            set             {                 number = value;                NotifyPropertyChanged("Number");            }        }        private int currentsize;        public int Currentsize        {            get { return currentsize; }            set            {                currentsize = value;                NotifyPropertyChanged("Currentsize");            }        }        private int total;        public int Total        {            get { return total; }            set            {                total = value;                NotifyPropertyChanged("Total");            }        }        private List
pages; public List
Pages { get { return pages; } set { pages = value; NotifyPropertyChanged("Pages"); } } private List
lst_user; public List
Lst_user { get { return lst_user; } set { lst_user = value; NotifyPropertyChanged("Lst_user"); } } private List
lst_bind; public List
Lst_bind { get { return lst_bind; } set { lst_bind = value; NotifyPropertyChanged("Lst_bind"); } } //负责监视属性的变化 public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string Propertyname) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(Propertyname)); } } public PageDataManager() { this.Number = 50; this.Lst_user = new List
(); for (int i = 0; i <= 1000; i++) { Lst_user.Add(new User() { Name="张三"+i.ToString(), Age=20, Address="中国河南" }); } //总页数=总数/每页显示的数 this.Total = Lst_user.Count()/Number; //初始化页数数组 this.Pages = new List
(); for (int i = 1; i <= Total; i++) { this.Pages.Add(new Pages() { Name=i.ToString(), PageSize=i}); } this.Currentsize = 1; Pager(Currentsize); } //分页方法 public void Pager(int cize) { this.Currentsize = cize; this.Lst_bind = this.Lst_user.Take(this.Number * cize).Skip(this.Number * (cize - 1)).ToList(); } }

MainPage.cs

public partial class MainWindow : Window    {        PageDataManager data = new PageDataManager();        public MainWindow()        {                      InitializeComponent();            this.DataContext = data;        }        private void Button_Click_1(object sender, RoutedEventArgs e)        {            data.Pager(((sender as Button).DataContext as Pages).PageSize);        }    }

 

转载于:https://www.cnblogs.com/wywnet/p/3495525.html

你可能感兴趣的文章
数据可视化(Echart) :柱状图、折线图、饼图等六种基本图表的特点及适用场合...
查看>>
IDEA 报错记录
查看>>
Yii中validator之scenario
查看>>
ie11兼容
查看>>
deprecated conversion from string constant to 'char*''
查看>>
(二)scala构造器和伴生对象
查看>>
MVC中使用RemoteAttribute异步远程验证
查看>>
ROP----The Solution For Ret2shellcode
查看>>
6 个设计原则分别是什么?每种设计原则体现的设计模式是哪个?
查看>>
js判断字符串是否有重复
查看>>
mac 安装ant
查看>>
图层混合模式之正片叠底、滤色
查看>>
环信java后台发送消息时提示msg 应该为JSONObject 的坑
查看>>
Delphi中TStringList类常用属性方法详解
查看>>
删除centos7中自带有python2.7
查看>>
Cisco IOS Debug Command Reference Command E through H
查看>>
Python处理时间 time && datetime 模块
查看>>
sql 删除所有表
查看>>
SGU107-987654321 problem
查看>>
白帽子讲WEB安全 第五章 点击劫持(Click Jacking)
查看>>