82 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			82 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using Prism.Commands;
							 | 
						|||
| 
								 | 
							
								using Prism.Mvvm;
							 | 
						|||
| 
								 | 
							
								using Prism.Regions;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								using System.Windows;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.Components.pagination
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class PaginationViewModel: BindableBase, IRegionMemberLifetime
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public static readonly DependencyProperty PageSizeProperty = DependencyProperty
							 | 
						|||
| 
								 | 
							
								        .Register("CurrentPage",
							 | 
						|||
| 
								 | 
							
								                typeof(int),
							 | 
						|||
| 
								 | 
							
								                typeof(Pagination),
							 | 
						|||
| 
								 | 
							
								                new FrameworkPropertyMetadata(10));
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        // 每页条数
							 | 
						|||
| 
								 | 
							
								        private int _pageSize = 10;
							 | 
						|||
| 
								 | 
							
								        // 当前页码
							 | 
						|||
| 
								 | 
							
								        private int _currentPage = 1;
							 | 
						|||
| 
								 | 
							
								        // 总条数
							 | 
						|||
| 
								 | 
							
								        private int _totalPages = 0;
							 | 
						|||
| 
								 | 
							
								        
							 | 
						|||
| 
								 | 
							
								        public int PageSize { get=> _pageSize;  set => SetProperty(ref _pageSize, value); }
							 | 
						|||
| 
								 | 
							
								        public int CurrentPage { get => _currentPage; set => SetProperty(ref _currentPage, value); }
							 | 
						|||
| 
								 | 
							
								        public int TotalPages { get => _totalPages; set => SetProperty(ref _totalPages, value); }
							 | 
						|||
| 
								 | 
							
								        // 总页数 
							 | 
						|||
| 
								 | 
							
								        public int PageCount
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => (int)Math.Ceiling((double)TotalPages/ PageSize);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public string InfoText
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => ((CurrentPage - 1) * PageSize + 1) + "-" + (CurrentPage * PageSize > TotalPages ? TotalPages : CurrentPage * PageSize) + "/" + TotalPages;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool KeepAlive => false;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand ToFirst
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                CurrentPage = 1;
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand ToPrve
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                CurrentPage -= 1;
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand ToNext
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                CurrentPage += 1;
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand ToEnd
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                CurrentPage = PageCount;
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |