add more detailed examples of pagination

This commit is contained in:
NaBian committed 2018-11-12 23:05:33 +08:00
1 parent 72bb3d1b48
commit faed201a2c
10 files changed
+161 -26

No files matched your search

@@ -0,0 +1,68 @@
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
{
/// <summary>
/// 所有数据
/// </summary>
private readonly List<DemoDataModel> _totalDataList;
/// <summary>
/// 显示的数据
/// </summary>
private List<DemoDataModel> _dataList;
/// <summary>
/// 显示的数据
/// </summary>
public List<DemoDataModel> DataList
{
get => _dataList;
set => Set(ref _dataList, value);
}
/// <summary>
/// 页码
/// </summary>
private int _pageIndex = 1;
/// <summary>
/// 页码
/// </summary>
public int PageIndex
{
get => _pageIndex;
set => Set(ref _pageIndex, value);
}
public PaginationDemoViewModel(DataService dataService)
{
_totalDataList = dataService.GetDemoDataList(100);
DataList = _totalDataList.Take(10).ToList();
}
/// <summary>
/// 页码改变命令
/// </summary>
public RelayCommand<FunctionEventArgs<int>> PageUpdatedCmd =>
new Lazy<RelayCommand<FunctionEventArgs<int>>>(() =>
new RelayCommand<FunctionEventArgs<int>>(PageUpdated)).Value;
/// <summary>
/// 页码改变
/// </summary>
private void PageUpdated(FunctionEventArgs<int> info)
{
DataList = _totalDataList.Skip((info.Info - 1) * 10).Take(10).ToList();
}
}
}
@@ -21,6 +21,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register<WindowDemoViewModel>();
SimpleIoc.Default.Register<ContributorsViewModel>();
SimpleIoc.Default.Register<StepBarDemoViewModel>();
SimpleIoc.Default.Register<PaginationDemoViewModel>();
}
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
@@ -42,6 +43,8 @@ namespace HandyControlDemo.ViewModel
public StepBarDemoViewModel StepBarDemo => ServiceLocator.Current.GetInstance<StepBarDemoViewModel>();
public PaginationDemoViewModel PaginationDemo => ServiceLocator.Current.GetInstance<PaginationDemoViewModel>();
#endregion
}
}