WPF DataGrid Pagination

前端 未结 1 1278
时光取名叫无心
时光取名叫无心 2021-01-14 15:55

I am using the example provided here StackOverflow related question, if i have an even number of items in the grid then it works all good, but if for instance i have an odd

相关标签:
1条回答
  • 2021-01-14 16:16

    The issue is not with GetItemAt method, leave it as it was:

        public override object GetItemAt(int index)
        {
            var offset = index % (this._itemsPerPage); 
    
            return this._innerList[this.StartIndex + offset];
        }
    

    The problem is with Count property override. In case it is the last page it should return the correct items left:

        public override int Count
        {
            get 
            {
                //all pages except the last
                if (CurrentPage < PageCount)
                    return this._itemsPerPage;
    
                //last page
                int remainder = _innerList.Count % this._itemsPerPage;
    
                return remainder == 0 ? this._itemsPerPage : remainder; 
            }
        }
    
    0 讨论(0)
提交回复
热议问题