Skip to content

Commit 30365df

Browse files
committed
Fix keyboard item selection for GridView
1 parent 6e3f346 commit 30365df

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,10 @@
456456
<UniformGridLayout
457457
x:Key="Layout_Icons"
458458
ItemsJustification="Start"
459+
MinItemWidth="128"
460+
MinItemHeight="128"
459461
MinColumnSpacing="8"
460-
MinRowSpacing="8" />
462+
MinRowSpacing="8"/>
461463

462464
<StackLayout x:Key="Layout_List" Spacing="3" />
463465

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.UI;
2222
using Microsoft.UI.Xaml.Media;
2323
using Windows.UI;
24+
using ABI.Windows.Media.PlayTo;
2425
using Microsoft.UI.Xaml.Controls.Primitives;
2526

2627
// To learn more about WinUI, the WinUI project structure,
@@ -512,20 +513,27 @@ private void SelectAndScrollTo(int index, bool focus)
512513

513514
CurrentPackageList.Select(index);
514515

515-
if (CurrentPackageList.ScrollView?.VerticalOffset > index * 39)
516+
double position;
517+
if (CurrentPackageList.Layout is StackLayout sl)
516518
{
517-
CurrentPackageList.ScrollView.ScrollTo(0, index * 39, new ScrollingScrollOptions(
518-
ScrollingAnimationMode.Disabled,
519-
ScrollingSnapPointsMode.Ignore
520-
));
519+
position = index * 39;
521520
}
522-
else if (CurrentPackageList.ScrollView?.VerticalOffset + CurrentPackageList.ScrollView?.ViewportHeight < (index + 1) * 39)
521+
else if (CurrentPackageList.Layout is UniformGridLayout gl)
523522
{
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}");
528527
}
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+
));
529537

530538
if (focus)
531539
Focus(FilteredPackages[index].Package);

0 commit comments

Comments
 (0)