using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SlnMesnac.WPF.Templates { public class PagenationModel : ObservableObject { private long total = 0; public long Total { get => total; set { total = value; RaisePropertyChanged(() => Total); } } private int page; public int Page { get => page; set { page = value; RaisePropertyChanged(() => Page); } } private int current = 1; public int Current { get => current; set { current = value; RaisePropertyChanged(() => Current); } } private List pageSizes = new List() { 10, 20, 30, 40, 50 }; public List PageSizes { get => pageSizes; set { pageSizes = value; RaisePropertyChanged(() => PageSizes); } } private int pageSize; public int PageSize { get => pageSize; set { pageSize = value; RaisePropertyChanged(() => PageSize); } } /// /// 上一页 /// private RelayCommand findPreCommand; public RelayCommand FindPreCommand { get => findPreCommand; set { findPreCommand = value; RaisePropertyChanged(() => FindPreCommand); } } /// /// 下一页 /// private RelayCommand findNextCommand; public RelayCommand FindNextCommand { get => findNextCommand; set { findNextCommand = value; RaisePropertyChanged(() => FindNextCommand); } } /// /// 目标页 /// private RelayCommand findTargetCommand; public RelayCommand FindTargetCommand { get => findTargetCommand; set { findTargetCommand = value; RaisePropertyChanged(() => FindTargetCommand); } } private ObservableCollection rows = new ObservableCollection(); public ObservableCollection Rows { get => rows; set { rows = value; RaisePropertyChanged(() => Rows); } } public int GetPageNumber() { return (current - 1) * PageSize; } public void computePage() { Page = Convert.ToInt32(Total / PageSize); if (Total % PageSize != 0) { Page += 1; } } } }