WinPager.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using FWindSoft.Handle;
  16. using FWindSoft.Wpf.Controls;
  17. namespace Test.Pager
  18. {
  19. /// <summary>
  20. /// WinPager.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class WinPager : Window
  23. {
  24. /*
  25. * 例子需要整理:
  26. * PageIndex变化引起联动处理。
  27. */
  28. PagerFilterControl m_FilterControl = new PagerFilterControl();
  29. public WinPager()
  30. {
  31. InitializeComponent();
  32. InitData();
  33. m_FilterControl.InitFilterAction = InitFilter;
  34. m_FilterControl.InitPagerAction = InitPager;
  35. m_FilterControl.UpdateData = UpdateData;
  36. m_FilterControl.FilterSetting["Name"] = string.Empty;
  37. //NavigationPager_OnPageIndexChanged(null, new PageChangedEventArgs() {CurrentPageIndex = 1});
  38. m_FilterControl.Refresh();
  39. }
  40. private void InitFilter(PagerFilterControl control)
  41. {
  42. Search.Text = control.FilterSetting["Name"].ToString();
  43. }
  44. private void InitPager(PagerFilterControl control)
  45. {
  46. //属性变化,控制不刷新页面
  47. Pager.CurrentPageIndex = control.CurrentPageIndex;
  48. }
  49. private void UpdateData(PagerFilterControl control)
  50. {
  51. if (DataSource == null)
  52. return;
  53. DataGrid.ItemsSource = null;
  54. int currentIndex = control.CurrentPageIndex;
  55. Collections = new ObservableCollection<Person>(DataSource.GetRange((currentIndex - 1) * 15, 15));
  56. DataGrid.ItemsSource = Collections;
  57. }
  58. private List<Person> DataSource;
  59. public ObservableCollection<Person> Collections;
  60. public void InitData()
  61. {
  62. int total = 100;
  63. List<Person> persons=new List<Person>();
  64. for (int i = 0; i < total; i++)
  65. {
  66. for (int j = 0; j < 15; j++)
  67. {
  68. persons.Add(new Person(){Name = "学生"+i.ToString()});
  69. }
  70. }
  71. DataSource = persons;
  72. Pager.TotalPageCount = 100;
  73. Pager.CurrentPageIndex = 1;
  74. }
  75. private void NavigationPager_OnPageIndexChanged(object sender, PageChangedEventArgs e)
  76. {
  77. //if (DataSource == null)
  78. // return;
  79. //DataGrid.ItemsSource = null;
  80. //int currentIndex = e.CurrentPageIndex;
  81. //Collections=new ObservableCollection<Person>(DataSource.GetRange((currentIndex-1)*15,15));
  82. //DataGrid.ItemsSource = Collections;
  83. //SearchTextBlock.SetSearchKey(Grid, e.CurrentPageIndex.ToString());
  84. m_FilterControl.CurrentPageIndex=Pager.CurrentPageIndex;
  85. m_FilterControl.PageInfoChanged();
  86. }
  87. private void BtnSearch_Click(object sender, RoutedEventArgs e)
  88. {
  89. m_FilterControl.FilterSetting["Name"] = Search.Text;
  90. m_FilterControl.FilterChanged();
  91. }
  92. }
  93. public class Person
  94. {
  95. public string Name { get; set; }
  96. public string Age { get; set; }
  97. }
  98. }