|
21 | 21 | using Microsoft.UI; |
22 | 22 | using Microsoft.UI.Xaml.Media; |
23 | 23 | using Windows.UI; |
24 | | -using ABI.Windows.Media.PlayTo; |
25 | 24 | using Microsoft.UI.Xaml.Controls.Primitives; |
26 | 25 |
|
27 | 26 | // To learn more about WinUI, the WinUI project structure, |
@@ -514,29 +513,33 @@ private void SelectAndScrollTo(int index, bool focus) |
514 | 513 | CurrentPackageList.Select(index); |
515 | 514 |
|
516 | 515 | double position; |
517 | | - if (CurrentPackageList.Layout is StackLayout sl) |
| 516 | + if (CurrentPackageList.Layout is StackLayout) |
518 | 517 | { |
519 | 518 | position = index * 39; |
520 | 519 | } |
521 | 520 | else if (CurrentPackageList.Layout is UniformGridLayout gl) |
522 | 521 | { |
523 | 522 | int columnCount = (int)((CurrentPackageList.ActualWidth - 8) / (gl.MinItemWidth + 8)); |
524 | | - int row = index / columnCount; |
| 523 | + int row = index / Math.Max(columnCount, 1); |
525 | 524 | position = Math.Max(row - 1, 0) * (gl.MinItemHeight + 8); |
526 | | - Debug.WriteLine($"pos: {position}, colCount:{columnCount}, {index / columnCount}"); |
| 525 | + Debug.WriteLine($"pos: {position}, colCount:{columnCount}, {row}"); |
527 | 526 | } |
528 | 527 | else |
529 | 528 | { |
530 | 529 | throw new InvalidCastException("The layout was not recognized"); |
531 | 530 | } |
532 | 531 |
|
533 | | - CurrentPackageList.ScrollView.ScrollTo(0, position, new ScrollingScrollOptions( |
534 | | - ScrollingAnimationMode.Disabled, |
535 | | - ScrollingSnapPointsMode.Ignore |
536 | | - )); |
537 | 532 |
|
538 | | - if (focus) |
539 | | - Focus(FilteredPackages[index].Package); |
| 533 | + if (position < CurrentPackageList.ScrollView.VerticalOffset || position > |
| 534 | + CurrentPackageList.ScrollView.VerticalOffset + CurrentPackageList.ScrollView.ActualHeight) |
| 535 | + { |
| 536 | + CurrentPackageList.ScrollView.ScrollTo(0, position, new ScrollingScrollOptions( |
| 537 | + ScrollingAnimationMode.Disabled, |
| 538 | + ScrollingSnapPointsMode.Ignore |
| 539 | + )); |
| 540 | + } |
| 541 | + |
| 542 | + if (focus) Focus(FilteredPackages[index].Package); |
540 | 543 | } |
541 | 544 |
|
542 | 545 | private void Focus(IPackage packageToFocus, int retryCount = 0) |
|
0 commit comments