123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Controls;
- using FurnaceUI.Views.Recipes;
- namespace FurnaceUI.Controls
- {
- partial class PaginationList : UserControl, INotifyPropertyChanged
- {
- #region 属性
- public List<BoatWaferItem> SubItems { private get; set; }
- public List<BoatWaferItem> Items
- {
- get { return (List<BoatWaferItem>)GetValue(ItemsProperty); }
- set { SetValue(ItemsProperty, value); }
- }
- public static readonly DependencyProperty ItemsProperty =
- DependencyProperty.Register("Items", typeof(List<BoatWaferItem>), typeof(PaginationList),new PropertyMetadata(null, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
- public int CurrentItemIndex
- {
- get { return (int)GetValue(CurrentItemIndexProperty); }
- set { SetValue(CurrentItemIndexProperty, value); }
- }
- public static readonly DependencyProperty CurrentItemIndexProperty =
- DependencyProperty.Register("CurrentItemIndex", typeof(int), typeof(PaginationList), new PropertyMetadata(-1, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
- #endregion
- #region 页面属性
- public int PageIndex { get; set; } = 1;
- public int PageCount { get; set; }
- public int RecordCount { get; set; }
- public int PageSize
- {
- get { return (int)GetValue(PageSizeProperty); }
- set { SetValue(PageSizeProperty, value); }
- }
- public static readonly DependencyProperty PageSizeProperty =
- DependencyProperty.Register("PageSize", typeof(int), typeof(PaginationList), new PropertyMetadata(1, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
- public bool IsListEnable
- {
- get { return (bool)GetValue(IsListEnableProperty); }
- set { SetValue(IsListEnableProperty, value); }
- }
- public static readonly DependencyProperty IsListEnableProperty =
- DependencyProperty.Register("IsListEnable", typeof(bool), typeof(PaginationList), new PropertyMetadata(true, new PropertyChangedCallback(RenderUpdateByPropertyChanged)));
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- #region 翻页命令
- public void NextPageCommand()
- {
- if (PageIndex < PageCount)
- {
- PageIndex = PageIndex + 1;
- TakePage();
- }
- }
- public void PreviousPageCommand()
- {
- if (PageIndex > 1)
- {
- PageIndex = PageIndex - 1; ;
- TakePage();
- }
- }
- public void HomePageCommand()
- {
- PageIndex = 1;
- TakePage();
- }
- public void TailPageCommand()
- {
- PageIndex = PageCount;
- TakePage();
- }
-
- #endregion
- public PaginationList()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 当属性刷新的时候,进行强制更新绘图
- /// </summary>
- /// <param name="dependency"></param>
- /// <param name="e"></param>
- public static void RenderUpdateByPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs e)
- {
- if (dependency is PaginationList hslThermometer)
- {
- hslThermometer.TakePage();
- }
- }
- private void TakePage()
- {
- if (PageSize <= 0 || Items == null || Items.Count<=0) return;
- PageCount = Items.Count / PageSize;
- RecordCount = Items.Count % PageSize;
- if (RecordCount > 0)
- PageCount += 1;
- if (PageIndex == PageCount)//最后一页
- {
- RecordCount = RecordCount == 0 ? PageSize : RecordCount;
- SubItems = Items.GetRange((PageIndex - 1) * PageSize, RecordCount);
- }
- else
- {
- SubItems = Items.GetRange((PageIndex - 1) * PageSize, PageSize);
- }
- SortSubItems();
- list.ItemsSource = SubItems;
- list.IsEnabled = IsListEnable;
- }
- private void SortSubItems()
- {
- BoatWaferItem[] TempList = new BoatWaferItem[SubItems.Count];
- var length = TempList.Length % 2 == 0 ? TempList.Length : TempList.Length + 1;
- for (int i = 0; i < TempList.Length; i++)
- {
- if(i%2==0)
- TempList[i] = SubItems[i/2];
- else
- TempList[i] = SubItems[i/2 + length / 2];
- }
-
- SubItems =new List<BoatWaferItem>(TempList);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Button btn = sender as Button;
- switch (btn.Tag)
- {
- case "HomePage":
- HomePageCommand();
- break;
- case "PrePage":
- PreviousPageCommand();
- break;
- case "NextPage":
- NextPageCommand();
- break;
- case "TailPage":
- TailPageCommand();
- break;
- }
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- Button btn = sender as Button;
- CurrentItemIndex = (int)btn.Tag;
- }
- }
- }
|