WPF 分页控件应用

 

效果图:   

前台代码:

<UserControl x:Class="Layout.UI.Comm.Pager"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" 
><Grid><Label Content="" Height="28" HorizontalAlignment="Left" Margin="0,0,0,0" Name="lblinfo" VerticalAlignment="Center" /><Button Content="上一页" Height="23" HorizontalAlignment="Left" Margin="172,0,0,0" Name="btnPrev" VerticalAlignment="Center" Width="75" Click="btnPrev_Click" /><Button Content="下一页" Height="23" HorizontalAlignment="Right" Margin="0,0,272,0" Name="btnNext" VerticalAlignment="Center" Width="75"  Click="btnNext_Click"/><TextBox Height="23" Margin="533,0,0,0" Name="txtCurrentPage" VerticalAlignment="Center" HorizontalAlignment="Left" Width="34" /><Button Content="转到" HorizontalAlignment="Right" Margin="0,0,96,0" Name="btnGo" Width="75" Height="23" Click="btnGo_Click" /><Label Content=""  HorizontalAlignment="Left" Margin="573,0,0,0" Name="label2" VerticalAlignment="Center" /><Label Content=""  Margin="0,0,68,0" Name="label3" VerticalAlignment="Center" HorizontalAlignment="Right"  /><Button Content="首页" Height="23" HorizontalAlignment="Left" Margin="91,0,0,0" Name="btnFirst" VerticalAlignment="Center" Width="75" Click="btnFirst_Click" /><Button Content="末页" Height="23" HorizontalAlignment="Left" Margin="334,0,0,0" Name="btnLast" VerticalAlignment="Center" Width="75" Click="btnLast_Click" />       </Grid>
</UserControl>后台代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace Layout.UI.Comm
{/// <summary>/// 申明委托/// </summary>/// <param name="e"></param>/// <returns></returns>public delegate int EventPagingHandler(EventPagingArg e);/// <summary>///wpf分页控件     /// </summary>public partial class Pager : UserControl{public Pager(){InitializeComponent();}public event EventPagingHandler EventPaging;/// <summary>/// 每页显示记录数/// </summary>private int _pageSize = 20;/// <summary>/// 每页显示记录数/// </summary>public int PageSize{get { return _pageSize; }set{_pageSize = value;GetPageCount();}}private int _nMax = 0;/// <summary>/// 总记录数/// </summary>public int NMax{get { return _nMax; }set{_nMax = value;GetPageCount();}}private int _pageCount = 0;/// <summary>/// 页数=总记录数/每页显示记录数/// </summary>public int PageCount{get { return _pageCount; }set { _pageCount = value; }}private int _pageCurrent = 0;/// <summary>/// 当前页号/// </summary>public int PageCurrent{get { return _pageCurrent; }set { _pageCurrent = value; }}private void GetPageCount(){ifthis.NMax > 0){this.PageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(this.NMax) / Convert.ToDouble(this.PageSize)));}else{this.PageCount = 0;}}/// <summary>/// 翻页控件数据绑定的办法/// </summary>public void Bind(){ifthis.EventPaging != null){this.NMax = this.EventPaging(new EventPagingArg(this.PageCurrent));}ifthis.PageCurrent > this.PageCount){this.PageCurrent = this.PageCount;}ifthis.PageCount == 1){this.PageCurrent = 1;}lblinfo.Content = ""+NMax+"" + this.PageCurrent.ToString() + "/" + this.PageCount.ToString()+"";this.txtCurrentPage.Text = this.PageCurrent.ToString();ifthis.PageCurrent == 1){this.btnPrev.IsEnabled = false;this.btnFirst.IsEnabled = false;}else{btnPrev.IsEnabled = true;btnFirst.IsEnabled = true;}ifthis.PageCurrent == this.PageCount){this.btnLast.IsEnabled = false;this.btnNext.IsEnabled = false;}else{btnLast.IsEnabled = true;btnNext.IsEnabled = true;}ifthis.NMax == 0){btnNext.IsEnabled = false;btnLast.IsEnabled = false;btnFirst.IsEnabled = false;btnPrev.IsEnabled = false;}}private void btnLast_Click(object sender, RoutedEventArgs e){PageCurrent = PageCount;this.Bind();}private void btnNext_Click(object sender, RoutedEventArgs e){this.PageCurrent += 1;if (PageCurrent > PageCount){PageCurrent = PageCount;}this.Bind();}private void btnGo_Click(object sender, RoutedEventArgs e){ifthis.txtCurrentPage.Text != null && txtCurrentPage.Text != ""){if (Int32.TryParse(txtCurrentPage.Text, out _pageCurrent)){this.Bind();}else{MessageBox.Show("输入数字格局错误!");}}}private void btnFirst_Click(object sender, RoutedEventArgs e){PageCurrent = 1;this.Bind();}private void btnPrev_Click(object sender, RoutedEventArgs e){PageCurrent -= 1;if (PageCurrent <= 0){PageCurrent = 1;}this.Bind();}}/// <summary>/// 自定义事务数据基类/// </summary>public class EventPagingArg : EventArgs{private int _intPageIndex;public EventPagingArg(int PageIndex){_intPageIndex = PageIndex;}}
}应用办法:private void Form_Loaded(object sender, RoutedEventArgs e){pager.PageSize = 12;pager.PageCurrent = 1;BindData();pager.NMax = total;}string strWhere = "IsPass=1";int total = 0;DataSet ds;private void BindData(){ds = OrderRecords.instance.GetList(pager.PageSize, pager.PageCurrent, strWhere, "Status asc,CurTime Desc"out total);gvOrderList.ItemsSource = ds.Tables[0].DefaultView;gvOrderList.CanUserAddRows = false;}private int pager_EventPaging(Comm.EventPagingArg e){int pagd = pager.PageCurrent;BindData();return total;}

 

转载于:https://www.cnblogs.com/wj-love/archive/2012/08/29/2662024.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274635.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

李宁品牌重塑_迈伊多品牌重塑的幕后

李宁品牌重塑This post was originally published on the Maido blog.这篇文章最初发表在 Maido博客上 。 You might notice that we’ve had a little facelift at Maido. Or you might not — and that’s totally fine. What we launched at the end of last year was not r…

搭建前端监控,如何采集异常数据?

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

产品经理如何提高创造力_如何提高产品设计师的创造力

产品经理如何提高创造力When David Kelley, Bill Moggridge, and Mike Nuttall founded IDEO, a consulting firm that would become one of the most innovative companies of the late 90s, they brought a new perspective in product development.当大卫凯利(David Kelley)…

Github上8个很棒的Vue项目

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

python 投资组合_成功投资组合的提示

python 投资组合Lately, I’ve had some free time during my job transition and have been reviewing a few of my friends’ design portfolios. Gradually, I found some common themes around the feedback I’ve given. And it occurred to me that others might find so…

Github上8个很棒的React项目

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

屏幕广播系统_如何设计系统,而不是屏幕

屏幕广播系统重点 (Top highlight)Over the past several decades, rapid advances in technology have dramatically enhanced the digital customer experience and their expectations. In the face of these heightened customer expectations, the role of the Interactio…

Umi 4 发布啦

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

Win32汇编--加载菜单资源

基本上的窗口都会有一个菜单,现在就来看看Win32汇编中是如何加载菜单的: 1>在工程中添加新的菜单资源 2>双击新添加的菜单资源进行编辑 3>菜单栏:Make->Compile RC来编译资源文件 4>导出资源中的ID号并写到数据段的.const中 5>下面是完整的源代码供参考:(工程…

Futura:从纳粹主义到月球-甚至更远

Reading the title of this article, the first thing that will come to mind for some is the funny expression of Buzz Lightyear — the Disney character — when he stretches his arms outwards and utters the famous phrase “To infinity and beyond!” before jump…

如何碎片化时间高效学习前端~

前端技术日新月异&#xff0c;发展迅速&#xff0c;作为一个与时俱进的前端工程师&#xff0c;需要不断的学习。这里强烈推荐几个前端开发工程师必备的优质公众号&#xff0c;希望对你有所帮助。大家可以像我一样&#xff0c;利用碎片时间阅读这些公众号的文章。前端从进阶到入…

爬取淘宝定价需要多久时间_如何对设计工作进行定价—停止收​​取时间并专注于价值

爬取淘宝定价需要多久时间Pricing creative work is a new concept for most freelancers who are starting their business. We are used to being paid for our time, either by an hourly wage or an annual salary. It makes it simple to quantify how much value we thin…

OEA 框架中集成的 RDLC 报表介绍

之前 OEA 一直用着一个 Delphi 开发的报表&#xff0c;所以两年来我一直就想在 OEA 中构建一个纯 .NET 的报表模块&#xff0c;但是一想到要开发复杂的报表引擎和设计器就觉得麻烦。所以这事一直拖着。最近开始研究一些成熟的报表引擎&#xff0c;经过对比&#xff0c;还是发现…

昆虫繁殖_“专为昆虫而生” –好奇!

昆虫繁殖重点 (Top highlight)The industry is changing towards a more agile approach and jacks of one trade can go extinct sooner than we think.该 行业正在发生变化 朝着更加灵活的方法和一个贸易的插Kong可以去灭绝快于我们的想法。 I’ve read a quote in a book r…

ECMAScript 2022 正式发布,有哪些新特性?

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

字母框如何影响UI内容的理解

What is your earliest memory of reading? Mine’s reading comics. I preferred films over books, I still do, but I seemed to have a fascination for comics. The experience of reading a comic, to me, was somewhere between watching a film and reading a novel, …

Vue2.7 本周发布?支持组合式 API、setup、css v-bind

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…

马上7月,诚邀新老朋友参加近5000人的源码共读活动!

大家好&#xff0c;我是若川。最近有不少新朋友关注我。诚邀各位新老读者朋友参加源码共读活动。活动介绍可以点击文末的阅读原文。https://juejin.cn/post/7079706017579139102很多人关注我的公众号是因为我写了一系列源码文章&#xff0c;想参与源码共读活动。虽然现在有近50…

hashmap 从头到尾_如何从头到尾设计一个简单的复古徽标

hashmap 从头到尾在纸上素描粗糙的概念 (Sketch rough concepts on paper) Start by sketching out a few ideas for your logo on paper. These don’t have to be detailed drawings. Instead, it’s about getting your ideas out quickly. In this early stage, you can ex…

Vue 2.7 正式发布,代号为 Naruto

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此加我微信ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。…