Ejemplo n.º 1
0
        private void btnNum_Click(object sender, RoutedEventArgs e)
        {
            if (PageChanged != null)
            {
                Button btn = sender as Button;
                PageControlItemModel itemModel = btn.CommandParameter as PageControlItemModel;
                if (itemModel.Page != Page)
                {
                    Page = itemModel.Page;
                    CalcPageNumList();

                    PageChangedEventArgs args = new PageChangedEventArgs(itemModel.Page);
                    PageChanged(sender, args);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算页码
        /// </summary>
        private void CalcPageNumList()
        {
            PageCount = (RecordCount - 1) / PageSize + 1;     //计算总页数PageCount

            _list = new List <PageControlItemModel>();

            //第一页
            PageControlItemModel item = new PageControlItemModel(1, Page);

            _list.Add(item);

            //当前页码连续页码
            for (int i = Page - ContinuousCount; i <= Page + ContinuousCount; i++)
            {
                if (i > 0 && i < PageCount)
                {
                    item = new PageControlItemModel(i, Page);
                    if (!_list.Exists(a => a.Page == item.Page))
                    {
                        _list.Add(item);
                    }
                }
            }

            //最后一页
            item = new PageControlItemModel(PageCount, Page);
            if (!_list.Exists(a => a.Page == item.Page))
            {
                _list.Add(item);
            }

            for (int i = _list.Count - 1; i > 0; i--)
            {
                if (_list[i].Page - _list[i - 1].Page > 1)
                {
                    _list.Insert(i, new PageControlItemModel(0, Page, 2));
                }
            }

            //上一页下一页
            if (Page == 1)
            {
                this.btnPrePage.IsEnabled  = false;
                this.btnPrePage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#88dddddd"));
            }
            else
            {
                this.btnPrePage.IsEnabled  = true;
                this.btnPrePage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"));
            }
            if (Page == PageCount)
            {
                this.btnNextPage.IsEnabled  = false;
                this.btnNextPage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#88dddddd"));
            }
            else
            {
                this.btnNextPage.IsEnabled  = true;
                this.btnNextPage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"));
            }

            _collection.Clear();
            _list.ForEach(a => { _collection.Add(a); });
        }