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