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.pswp.cn/news/274635.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274635.shtml
英文地址,請注明出處:http://en.pswp.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余篇源碼文章。歷史面試系列。…

域名解析文件hosts文件是什么?如何修改hosts文件?

如何修改hosts文件&#xff1f; hosts文件的位置&#xff1a;xp,2000等系統在 C:\windows\system32\drivers\etc 文件夾中找到Hosts文件并用記事本打開(Windows 9x/Me系統在C:\Windows文件夾中找)按照 ip地址 域名 的格式添加單獨的一行記錄。例如72.14.219.190 www.hbcms.net…

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余篇源碼文章。歷史面試系列。…

騰訊的筆試題一道

搜羅了一些騰訊的筆試題目 題目是這樣的&#xff1a;在如下8*6的矩陣中&#xff0c;請計算從A移動到B一共有多少種走法&#xff1f;要求每次只能向上揮著向右移動一格&#xff0c;并且不能經過P&#xff1b; B P …

屏幕廣播系統_如何設計系統,而不是屏幕

屏幕廣播系統重點 (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余篇源碼文章。歷史面試系列。…

linux中用戶忘記root的密碼--ubuntu版本

基于ubuntu操作系統的情況&#xff0c;當用戶忘記root密碼后&#xff0c; 在普通用戶登陸后 輸入sudu su root 之后系統要求輸入當前用戶的密碼&#xff0c;用戶輸入密碼后&#xff0c;就可以進入root的模式了 就可以操作任何任務。轉載于:https://www.cnblogs.com/zhengyn/arc…