using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Txgy.Controls
{
public class PaginationModel : BindableBase
{
#region 构造函数
public PaginationModel() { }
///
///
///
/// 导航到某页,可以知道需要请求哪一个页面的数据
/// 修改每页的显示数量的时候触发请求数据
public PaginationModel(ICommand navCommand, ICommand countChangeCommand)
{
NavCommand = navCommand;
CountPerPageChangeCommand = countChangeCommand;
}
#endregion
public ICommand NavCommand { get; set; }
public ICommand CountPerPageChangeCommand { get; set; }
///
/// 所有的可显示页 240 24 1-24
///
public ObservableCollection Pages { get; set; } = new ObservableCollection();
private int _countPerPage = 10;
///
/// 每页的显示数据条数
///
public int CountPerPage
{
get => _countPerPage;
set { SetProperty(ref _countPerPage, value); }
}
private int _previousIndex;
///
/// 前一条数据的Index 如果当前Index=2 1 3
///
public int PreviousIndex
{
get => _previousIndex;
set { SetProperty(ref _previousIndex, value); }
}
private int _nextIndex;
public int NextIndex
{
get => _nextIndex;
set { SetProperty(ref _nextIndex, value); }
}
///
/// 也可以通过命令的
///
private bool _isCanPrevious = true;
public bool IsCanPrevious
{
get => _isCanPrevious;
set { SetProperty(ref _isCanPrevious, value); }
}
private bool _isCanNext = true;
public bool IsCanNext
{
get => _isCanNext;
set { SetProperty(ref _isCanNext, value); }
}
///
/// 填充页码
///
/// 总记录数(数据库中的当的所有有效数据的条数)
/// 当前页码
public void FillPages(int sumCount, int pageCode)
{
IsCanPrevious = true;
IsCanNext = true;
PreviousIndex = pageCode - 1;
NextIndex = pageCode + 1;
// 总页数
int pageCount = (int)Math.Ceiling(sumCount * 1.0 / CountPerPage);
if (pageCode > pageCount) pageCode = pageCount;
// 处理前一页和后一页按钮的可用性
if (pageCode == 1)
IsCanPrevious = false;
if (pageCode == pageCount)
IsCanNext = false;
List