using System;
using System.Collections.Generic;
using System.Linq;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using HandyControl.Data;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class PaginationDemoViewModel : ViewModelBase
{
///
/// 所有数据
///
private readonly List _totalDataList;
///
/// 显示的数据
///
private List _dataList;
///
/// 显示的数据
///
public List DataList
{
get => _dataList;
set => Set(ref _dataList, value);
}
///
/// 页码
///
private int _pageIndex = 1;
///
/// 页码
///
public int PageIndex
{
get => _pageIndex;
set => Set(ref _pageIndex, value);
}
public PaginationDemoViewModel(DataService dataService)
{
_totalDataList = dataService.GetDemoDataList(100);
DataList = _totalDataList.Take(10).ToList();
}
///
/// 页码改变命令
///
public RelayCommand> PageUpdatedCmd =>
new Lazy>>(() =>
new RelayCommand>(PageUpdated)).Value;
///
/// 页码改变
///
private void PageUpdated(FunctionEventArgs info)
{
DataList = _totalDataList.Skip((info.Info - 1) * 10).Take(10).ToList();
}
}
}