PaginationClass.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Namordnik.Class
  8. {
  9. class PaginationClass : INotifyPropertyChanged
  10. {
  11. public event PropertyChangedEventHandler PropertyChanged;
  12. static int countitems = 4;
  13. public int[] NPage { get; set; } = new int[countitems];
  14. public string[] Visible { get; set; } = new string[countitems];
  15. public string[] Bold { get; set; } = new string[countitems];
  16. int countpages;
  17. public int CountPages
  18. {
  19. get => countpages;
  20. set
  21. {
  22. countpages = value;
  23. for (int i = 1; i < countitems; i++)
  24. {
  25. if (CountPages <= i)
  26. {
  27. Visible[i] = "Hidden";
  28. }
  29. else
  30. {
  31. Visible[i] = "Visible";
  32. }
  33. }
  34. }
  35. }
  36. int countpage;
  37. public int CountPage
  38. {
  39. get => countpage;
  40. set
  41. {
  42. countpage = value;
  43. if (Countlist % value == 0)
  44. {
  45. CountPages = Countlist / value;
  46. }
  47. else
  48. {
  49. CountPages = Countlist / value + 1;
  50. }
  51. }
  52. }
  53. int countlist;
  54. public int Countlist
  55. {
  56. get => countlist;
  57. set
  58. {
  59. countlist = value;
  60. if (value % CountPage == 0)
  61. {
  62. CountPages = value / CountPage;
  63. }
  64. else
  65. {
  66. CountPages = 1 + value / CountPage;
  67. }
  68. }
  69. }
  70. int currentpage;
  71. public int CurrentPage
  72. {
  73. get => currentpage;
  74. set
  75. {
  76. currentpage = value;
  77. if (currentpage < 1)
  78. {
  79. currentpage = 1;
  80. }
  81. if (currentpage >= CountPages)
  82. {
  83. currentpage = CountPages;
  84. }
  85. for (int i = 0; i < countitems; i++)
  86. {
  87. if (currentpage < (1 + countitems / 2) || CountPages < countitems) NPage[i] = i + 1;
  88. else if (currentpage > CountPages - (countitems / 2 + 1)) NPage[i] = CountPages - (countitems - 1) + i;
  89. else NPage[i] = currentpage + i - (countitems / 2);
  90. }
  91. for (int i = 0; i < countitems; i++)
  92. {
  93. if (NPage[i] == currentpage) Bold[i] = "ExtraBold";
  94. else Bold[i] = "Regular";
  95. }
  96. PropertyChanged(this, new PropertyChangedEventArgs("NPage"));
  97. PropertyChanged(this, new PropertyChangedEventArgs("Visible"));
  98. PropertyChanged(this, new PropertyChangedEventArgs("Bold"));
  99. }
  100. }
  101. public PaginationClass() // контруктор
  102. {
  103. for (int i = 0; i < countitems; i++)
  104. {
  105. Visible[i] = "Visible";
  106. NPage[i] = i + 1;
  107. Bold[i] = "Regular";
  108. }
  109. currentpage = 1;
  110. countpage = 1;
  111. countlist = 1;
  112. }
  113. }
  114. }