Skip to content

Commit ff16c74

Browse files
authored
Fixed a crash that would occur when using the selection rectangle in an empty folder (#2162)
1 parent f9a9292 commit ff16c74

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Files/UserControls/RectangleSelection.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventAr
194194
var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).SkipWhile(x => x.Value.Y <= verticalOffset + uiElement.ActualHeight).Select(x => x.Key).FirstOrDefault();
195195
if (item == null)
196196
{
197-
// Last loaded item is fully visible, ge thet next one from bound item source
198-
var index = dataGridRowsPosition.OrderBy(x => x.Value.Y).Last().Key.GetIndex();
199-
var source = (System.Collections.IList)uiElement.ItemsSource;
200-
uiElement.ScrollIntoView(source[Math.Min(Math.Max(index + 1, 0), source.Count - 1)], null);
197+
if (dataGridRowsPosition.Any())
198+
{
199+
// Last loaded item is fully visible, ge thet next one from bound item source
200+
var index = dataGridRowsPosition.OrderBy(x => x.Value.Y).Last().Key.GetIndex();
201+
var source = (System.Collections.IList)uiElement.ItemsSource;
202+
uiElement.ScrollIntoView(source[Math.Min(Math.Max(index + 1, 0), source.Count - 1)], null);
203+
}
201204
}
202205
else
203206
{
@@ -211,10 +214,13 @@ private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventAr
211214
var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).TakeWhile(x => x.Value.Y + x.Value.Height <= scrollBar.Value).Select(x => x.Key).LastOrDefault();
212215
if (item == null)
213216
{
214-
// First loaded item is fully visible, ge thet previous one from bound item source
215-
var index = dataGridRowsPosition.OrderBy(x => x.Value.Y).First().Key.GetIndex();
216-
var source = (System.Collections.IList)uiElement.ItemsSource;
217-
uiElement.ScrollIntoView(source[Math.Min(Math.Max(index - 1, 0), source.Count - 1)], null);
217+
if (dataGridRowsPosition.Any())
218+
{
219+
// First loaded item is fully visible, ge thet previous one from bound item source
220+
var index = dataGridRowsPosition.OrderBy(x => x.Value.Y).First().Key.GetIndex();
221+
var source = (System.Collections.IList)uiElement.ItemsSource;
222+
uiElement.ScrollIntoView(source[Math.Min(Math.Max(index - 1, 0), source.Count - 1)], null);
223+
}
218224
}
219225
else
220226
{

0 commit comments

Comments
 (0)