DataPager 分页控件
代码下载地址:http://download.youkuaiyun.com/detail/w_wang_w/8473825
cs部分
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
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 Common.Controls
{
/// <summary>
/// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
///
/// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
/// 元素中:
///
/// xmlns:MyNamespace="clr-namespace:Common.Controls"
///
///
/// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
/// 元素中:
///
/// xmlns:MyNamespace="clr-namespace:Common.Controls.DataPage;assembly=Common.Controls.DataPage"
///
/// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
/// 并重新生成以避免编译错误:
///
/// 在解决方案资源管理器中右击目标项目,然后依次单击
/// “添加引用”->“项目”->[浏览查找并选择此项目]
///
///
/// 步骤 2)
/// 继续操作并在 XAML 文件中使用控件。
///
/// <MyNamespace:CustomControl1/>
///
/// </summary>
///
//定义一委托类型
public delegate IEnumerable PageChangeEventHandler(int pageIndex, int pageSize);
public delegate int CountEventHandler();
[TemplatePart(Name = PART_BtnJump, Type = typeof(Button))]
public class DataPager : Control,INotifyPropertyChanged
{
#region 构造函数
static DataPager()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DataPager), new FrameworkPropertyMetadata(typeof(DataPager)));
}
public DataPager()
{
// Keyboard.AddKeyDownHandler(this, OnKeyDown);
// Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement);
this.Loaded += DataPager_Loaded;
}
#endregion
#region 私有变量
private const string PART_BtnJump = "PART_BtnJump";
private const string PART_BtnPrePage = "PART_BtnPrePage";
private const string PART_BtnNextPage = "PART_BtnNextPage";
private const string PART_LblPageIndex = "PART_LblPageIndex";
private const string PART_LblPageCount = "PART_LblPageCount";
private const string PART_BtnJumpOK = "PART_BtnJumpOK";
private const string PART_TxtPageIndex = "PART_TxtPageIndex";
private ToggleButton btnJump;
private Button btnPrePage;
private Button btnNextPage;
private Label lblPageIndex;
private Label lblPageCount;
private Button btnJumpOK;
private TextBox txtPageIndex;
private IEnumerable m_curPageData;
#endregion
#region 依赖属性
public static readonly DependencyProperty IsVisablePopupJumpProperty = DependencyProperty.Register("IsVisablePopupJump", typeof(bool), typeof(DataPager), new UIPropertyMetadata(false, null));
/// <summary>
/// 依赖属性:单页最大数据量
/// </summary>
public static readonly DependencyProperty PageSizeProperty = DependencyProperty.Register("PageSize", typeof(int), typeof(DataPager), new PropertyMetadata(new PropertyChangedCallback(DataPager.PageSizeChanged)));
/// <summary>
/// 每一页的数据数量
/// </summary>
public int PageSize
{
get
{
return (int)GetValue(PageSizeProperty);
}
set
{
SetValue(PageSizeProperty, value);
}
}
private static void PageSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion
#region 属性
public bool IsVisablePopupJump
{
get
{
return (bool)GetValue(IsVisablePopupJumpProperty);
}
set
{
SetValue(IsVisablePopupJumpProperty, value);
}
}
private int pageIndex = 1;
/// <summary>
/// 当前页面索引
/// </summary>
public int PageIndex
{
get
{
&