-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix Incorrect Scrolling Behavior in CollectionView ScrollTo Method Using Index Value #27246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jfversluis
merged 6 commits into
dotnet:inflight/current
from
Shalini-Ashokan:fix-27117
Feb 20, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
db3dfc2
Fix the scrollTo method is not scroll correctly using index value
Shalini-Ashokan 12f0567
modified the test case for CV2
Shalini-Ashokan 77aa71b
Added the images
Shalini-Ashokan 7b0e2a3
Committed the images
Shalini-Ashokan 8a82d70
Committed the images
Shalini-Ashokan 2502724
Update Issue27117 test to verify header vs. first item scroll
kubaflo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Controls/tests/TestCases.HostApp/Issues/Issue27117.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue27117" | ||
| xmlns:cv2="clr-namespace:Maui.Controls.Sample" | ||
| xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"> | ||
|
|
||
| <ContentPage.BindingContext> | ||
| <local:_27117MainViewModel/> | ||
| </ContentPage.BindingContext> | ||
|
|
||
| <Grid RowDefinitions="Auto,*"> | ||
| <Button Grid.Row="0" | ||
| Text="Scroll to First Item" | ||
| AutomationId="ScrollToFirstItemButton" | ||
| Clicked="ScrollToFirstItem_Clicked"/> | ||
|
|
||
| <cv2:CollectionView2 Grid.Row="1" | ||
| AutomationId="collectionView" | ||
| x:Name="collectionView" | ||
| x:DataType="local:_27117MainViewModel" | ||
| ItemsSource="{Binding _27117People}" | ||
| BackgroundColor="DarkGray"> | ||
| <cv2:CollectionView2.Header> | ||
| <StackLayout BackgroundColor="LightGray"> | ||
| <Label Margin="10,0,0,0" | ||
| Text="People" | ||
| AutomationId="HeaderLabel" | ||
| FontSize="Header" | ||
| FontAttributes="Bold"/> | ||
| </StackLayout> | ||
| </cv2:CollectionView2.Header> | ||
|
|
||
| <cv2:CollectionView2.ItemTemplate> | ||
| <DataTemplate x:DataType="local:_27117Person"> | ||
| <VerticalStackLayout> | ||
| <Label Text="{Binding Name}" | ||
| AutomationId="{Binding Name}" | ||
| FontSize="Medium"/> | ||
| <Rectangle HeightRequest="2" | ||
| BackgroundColor="Black"/> | ||
| </VerticalStackLayout> | ||
| </DataTemplate> | ||
| </cv2:CollectionView2.ItemTemplate> | ||
|
|
||
| <cv2:CollectionView2.Footer> | ||
| <StackLayout BackgroundColor="LightGray"> | ||
| <Label Margin="10,0,0,0" | ||
| Text="Footer" | ||
| FontSize="Header" | ||
| FontAttributes="Bold"/> | ||
| </StackLayout> | ||
| </cv2:CollectionView2.Footer> | ||
| </cv2:CollectionView2> | ||
| </Grid> | ||
| </ContentPage> |
43 changes: 43 additions & 0 deletions
43
src/Controls/tests/TestCases.HostApp/Issues/Issue27117.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.Collections.ObjectModel; | ||
| using System.Diagnostics; | ||
| using System.Windows.Input; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 27117, "CollectionView ScrollTo not working under android", PlatformAffected.All)] | ||
| public partial class Issue27117 : ContentPage | ||
| { | ||
| public Issue27117() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| private void ScrollToFirstItem_Clicked(object sender, EventArgs e) | ||
| { | ||
| collectionView.ScrollTo(0, position: ScrollToPosition.Start, animate: false); | ||
| } | ||
| } | ||
|
|
||
| public class _27117MainViewModel : BindableObject | ||
| { | ||
| public ObservableCollection<_27117Person> _27117People { get; set; } | ||
| public _27117MainViewModel() | ||
| { | ||
| _27117People = new ObservableCollection<_27117Person>(); | ||
| for (int i = 0; i < 100; i++) | ||
| { | ||
| _27117People.Add(new _27117Person($"Person {i}")); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class _27117Person | ||
| { | ||
| public string Name { get; set; } | ||
|
|
||
| public _27117Person(string name) | ||
| { | ||
| Name = name; | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27117.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue27117 : _IssuesUITest | ||
| { | ||
| public Issue27117(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "CollectionView ScrollTo not working under android"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void ScrollToIndexZeroShowsFirstItemNotHeader() | ||
| { | ||
| // Wait for CollectionView to load | ||
| App.WaitForElement("collectionView"); | ||
|
|
||
| // Get Y position of header | ||
| var headerRect = App.WaitForElement("HeaderLabel").GetRect(); | ||
| var headerY = headerRect.Y; | ||
|
|
||
| // Get initial Y position of "Person 0" | ||
| var initialRect = App.WaitForElement("Person 0").GetRect(); | ||
| var initialY = initialRect.Y; | ||
|
|
||
| // Person 0 should be below the header initially | ||
| Assert.That(initialY, Is.GreaterThan(headerY), | ||
| "Person 0 should be below header initially"); | ||
|
|
||
| // Tap button to scroll to index 0 with ScrollToPosition.Start | ||
| App.Tap("ScrollToFirstItemButton"); | ||
| Task.Delay(1000).Wait(); | ||
|
|
||
| // Get Y position after ScrollTo(0) | ||
| var afterScrollToRect = App.WaitForElement("Person 0").GetRect(); | ||
| var afterScrollToY = afterScrollToRect.Y; | ||
|
|
||
| Assert.That(afterScrollToY, Is.LessThan(initialY), | ||
| $"ScrollTo(0) should scroll Person 0 to top, not push it down. " + | ||
| $"Initial Y={initialY}, After ScrollTo Y={afterScrollToY}. " + | ||
| $"If Y increased, the header was incorrectly treated as index 0."); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix only addresses Android. The same issue likely exists on iOS, Windows, and MacCatalyst platforms. The iOS handler is in
src/Controls/src/Core/Handlers/Items/iOS/ItemsViewHandler.iOS.csand Windows handler insrc/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs. Both need similar fixes to account for headers when scrolling by index.Check if the header offset needs to be applied in:
ItemsViewHandler.iOS.cs-ScrollToRequestedmethodItemsViewHandler.Windows.cs-ScrollTomethodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue does not reproduce on Windows and iOS CV2.