Skip to content

Commit d68c78e

Browse files
committed
fix(demo): index out of range when start index + count > overallCount
1 parent 76a2c5f commit d68c78e

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

DataVirtualizationDemo/Window1.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public IList<Person> LoadRange(int startIndex, int count, SortDescriptionCollect
108108
SortDescription sortDescription = sortDescriptions == null || sortDescriptions.Count == 0 ? new SortDescription() : sortDescriptions[0];
109109
ListSortDirection direction = string.IsNullOrEmpty(sortDescription.PropertyName) ? ListSortDirection.Ascending : sortDescription.Direction;
110110

111+
count = Math.Min(count, overallCount - startIndex);
112+
111113
Person[] persons = new Person[count];
112114
for (int i = 0; i < count; i++)
113115
{

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ public IList<Person> LoadRange(int startIndex, int count, SortDescriptionCollect
229229
SortDescription sortDescription = sortDescriptions == null || sortDescriptions.Count == 0 ? new SortDescription() : sortDescriptions[0];
230230
ListSortDirection direction = string.IsNullOrEmpty(sortDescription.PropertyName) ? ListSortDirection.Ascending : sortDescription.Direction;
231231

232+
count = Math.Min(count, overallCount - startIndex);
233+
232234
Person[] persons = new Person[count];
233235
for (int i = 0; i < count; i++)
234236
{

0 commit comments

Comments
 (0)