-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix VerticalOffset Update When Modifying CollectionView.ItemsSource While Scrolled #26782
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
Changes from 16 commits
48fdf2e
d43f439
8f9c2f7
b1c8893
fa23ad1
91ab637
ed0e054
7fe5874
8b03440
4809a93
95706ec
7d56aaf
05dcd7d
95a0aa0
26d99d4
f025a6e
f245cd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,12 +30,9 @@ public override void Scrolled(UIScrollView scrollView) | |||||||||||||||||
| { | ||||||||||||||||||
| var (visibleItems, firstVisibleItemIndex, centerItemIndex, lastVisibleItemIndex) = GetVisibleItemsIndex(); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!visibleItems) | ||||||||||||||||||
| return; | ||||||||||||||||||
|
|
||||||||||||||||||
| var contentInset = scrollView.ContentInset; | ||||||||||||||||||
| var contentOffsetX = scrollView.ContentOffset.X + contentInset.Left; | ||||||||||||||||||
| var contentOffsetY = scrollView.ContentOffset.Y + contentInset.Top; | ||||||||||||||||||
| var contentOffsetX = !visibleItems ? 0 : scrollView.ContentOffset.X + contentInset.Left; | ||||||||||||||||||
| var contentOffsetY = !visibleItems ? 0 : scrollView.ContentOffset.Y + contentInset.Top; | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| // Reset previous offsets if there are no visible items to ensure correct delta calculation when items are re-added | |
| if (!visibleItems) | |
| { | |
| PreviousHorizontalOffset = 0; | |
| PreviousVerticalOffset = 0; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?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" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x:Class="Maui.Controls.Sample.Issues.Issue21708"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Grid> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Grid.RowDefinitions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <RowDefinition Height="Auto" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <RowDefinition Height="Auto" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <RowDefinition /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Grid.RowDefinitions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Grid.ColumnDefinitions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ColumnDefinition /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ColumnDefinition /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ColumnDefinition /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Grid.ColumnDefinitions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Grid.Row="0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Grid.Column="0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Margin="10" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AutomationId="Fill" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Clicked="FillButton_OnClicked" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text="Fill" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Grid.Row="0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Grid.Column="2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Margin="10" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AutomationId="Empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Clicked="EmptyButton_OnClicked" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text="Empty" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Label | |
| <Label |
Copilot
AI
Dec 8, 2025
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.
The XAML binding ItemsSource="{Binding Items}" is incorrect. The code-behind sets CollectionView.ItemsSource = _items directly in the constructor (line 17), so the XAML binding will have no effect. Either remove the direct assignment in the code-behind and rely on the XAML binding with a proper Items property, or remove the XAML binding and keep the code-behind assignment.
| ItemsSource="{Binding Items}" |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces while others use tabs. The entire file should use consistent tab indentation.
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | |
| x:Class="Maui.Controls.Sample.Issues.Issue21708"> | |
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition /> | |
| </Grid.RowDefinitions> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| </Grid.ColumnDefinitions> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="0" | |
| Margin="10" | |
| AutomationId="Fill" | |
| Clicked="FillButton_OnClicked" | |
| Text="Fill" /> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="2" | |
| Margin="10" | |
| AutomationId="Empty" | |
| Clicked="EmptyButton_OnClicked" | |
| Text="Empty" /> | |
| <Label | |
| Grid.Row="1" | |
| Grid.Column="0" | |
| AutomationId="VerticalOffsetLabel" | |
| Text="VerticalOffset: " /> | |
| <Label AutomationId="Label" | |
| Grid.ColumnSpan="2" | |
| Grid.Row="1" | |
| HorizontalTextAlignment="Start" | |
| Grid.Column="1" | |
| Text="{Binding VerticalOffset}" /> | |
| <CollectionView AutomationId="CollectionView" | |
| x:Name="CollectionView" | |
| Grid.Row="2" | |
| Grid.Column="0" | |
| Grid.ColumnSpan="3" | |
| ItemsSource="{Binding Items}" | |
| Scrolled="CollectionView_OnScrolled"> | |
| <CollectionView.ItemTemplate> | |
| <DataTemplate> | |
| <Label | |
| Margin="10" | |
| FontSize="Default" | |
| HeightRequest="20" | |
| HorizontalTextAlignment="Center" | |
| Text="{Binding .}" | |
| TextColor="RoyalBlue" /> | |
| </DataTemplate> | |
| </CollectionView.ItemTemplate> | |
| </CollectionView> | |
| </Grid> | |
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | |
| x:Class="Maui.Controls.Sample.Issues.Issue21708"> | |
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition /> | |
| </Grid.RowDefinitions> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| </Grid.ColumnDefinitions> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="0" | |
| Margin="10" | |
| AutomationId="Fill" | |
| Clicked="FillButton_OnClicked" | |
| Text="Fill" /> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="2" | |
| Margin="10" | |
| AutomationId="Empty" | |
| Clicked="EmptyButton_OnClicked" | |
| Text="Empty" /> | |
| <Label | |
| Grid.Row="1" | |
| Grid.Column="0" | |
| AutomationId="VerticalOffsetLabel" | |
| Text="VerticalOffset: " /> | |
| <Label AutomationId="Label" | |
| Grid.ColumnSpan="2" | |
| Grid.Row="1" | |
| HorizontalTextAlignment="Start" | |
| Grid.Column="1" | |
| Text="{Binding VerticalOffset}" /> | |
| <CollectionView AutomationId="CollectionView" | |
| x:Name="CollectionView" | |
| Grid.Row="2" | |
| Grid.Column="0" | |
| Grid.ColumnSpan="3" | |
| ItemsSource="{Binding Items}" | |
| Scrolled="CollectionView_OnScrolled"> | |
| <CollectionView.ItemTemplate> | |
| <DataTemplate> | |
| <Label | |
| Margin="10" | |
| FontSize="Default" | |
| HeightRequest="20" | |
| HorizontalTextAlignment="Center" | |
| Text="{Binding .}" | |
| TextColor="RoyalBlue" /> | |
| </DataTemplate> | |
| </CollectionView.ItemTemplate> | |
| </CollectionView> | |
| </Grid> |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces while others use tabs. The entire file should use consistent tab indentation.
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | |
| x:Class="Maui.Controls.Sample.Issues.Issue21708"> | |
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition /> | |
| </Grid.RowDefinitions> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| </Grid.ColumnDefinitions> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="0" | |
| Margin="10" | |
| AutomationId="Fill" | |
| Clicked="FillButton_OnClicked" | |
| Text="Fill" /> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="2" | |
| Margin="10" | |
| AutomationId="Empty" | |
| Clicked="EmptyButton_OnClicked" | |
| Text="Empty" /> | |
| <Label | |
| Grid.Row="1" | |
| Grid.Column="0" | |
| AutomationId="VerticalOffsetLabel" | |
| Text="VerticalOffset: " /> | |
| <Label AutomationId="Label" | |
| Grid.ColumnSpan="2" | |
| Grid.Row="1" | |
| HorizontalTextAlignment="Start" | |
| Grid.Column="1" | |
| Text="{Binding VerticalOffset}" /> | |
| <CollectionView AutomationId="CollectionView" | |
| x:Name="CollectionView" | |
| Grid.Row="2" | |
| Grid.Column="0" | |
| Grid.ColumnSpan="3" | |
| ItemsSource="{Binding Items}" | |
| Scrolled="CollectionView_OnScrolled"> | |
| <CollectionView.ItemTemplate> | |
| <DataTemplate> | |
| <Label | |
| Margin="10" | |
| FontSize="Default" | |
| HeightRequest="20" | |
| HorizontalTextAlignment="Center" | |
| Text="{Binding .}" | |
| TextColor="RoyalBlue" /> | |
| </DataTemplate> | |
| </CollectionView.ItemTemplate> | |
| </CollectionView> | |
| </Grid> | |
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | |
| x:Class="Maui.Controls.Sample.Issues.Issue21708"> | |
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition Height="Auto" /> | |
| <RowDefinition /> | |
| </Grid.RowDefinitions> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| <ColumnDefinition /> | |
| </Grid.ColumnDefinitions> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="0" | |
| Margin="10" | |
| AutomationId="Fill" | |
| Clicked="FillButton_OnClicked" | |
| Text="Fill" /> | |
| <Button | |
| Grid.Row="0" | |
| Grid.Column="2" | |
| Margin="10" | |
| AutomationId="Empty" | |
| Clicked="EmptyButton_OnClicked" | |
| Text="Empty" /> | |
| <Label | |
| Grid.Row="1" | |
| Grid.Column="0" | |
| AutomationId="VerticalOffsetLabel" | |
| Text="VerticalOffset: " /> | |
| <Label AutomationId="Label" | |
| Grid.ColumnSpan="2" | |
| Grid.Row="1" | |
| HorizontalTextAlignment="Start" | |
| Grid.Column="1" | |
| Text="{Binding VerticalOffset}" /> | |
| <CollectionView AutomationId="CollectionView" | |
| x:Name="CollectionView" | |
| Grid.Row="2" | |
| Grid.Column="0" | |
| Grid.ColumnSpan="3" | |
| ItemsSource="{Binding Items}" | |
| Scrolled="CollectionView_OnScrolled"> | |
| <CollectionView.ItemTemplate> | |
| <DataTemplate> | |
| <Label | |
| Margin="10" | |
| FontSize="Default" | |
| HeightRequest="20" | |
| HorizontalTextAlignment="Center" | |
| Text="{Binding .}" | |
| TextColor="RoyalBlue" /> | |
| </DataTemplate> | |
| </CollectionView.ItemTemplate> | |
| </CollectionView> | |
| </Grid> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Collections.ObjectModel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Maui.Controls.Sample.Issues | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [Issue(IssueTracker.Github, 21708, "CollectionView.Scrolled event offset isn't correctly reset when items change", PlatformAffected.All)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public partial class Issue21708 : ContentPage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ObservableCollection<int> _items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double _verticalOffset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double _verticalOffset; | |
| double _verticalOffset; |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces for indentation while the rest of the file uses tabs. These should be indented with tabs to match the surrounding code.
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) | |
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces for indentation while the rest of the file uses tabs. These should be indented with tabs to match the surrounding code.
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) | |
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces for indentation while the rest of the file uses tabs. These should be indented with tabs to match the surrounding code.
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) | |
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces for indentation while the rest of the file uses tabs. These should be indented with tabs to match the surrounding code.
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) | |
| double _verticalOffset; | |
| public Issue21708() | |
| { | |
| InitializeComponent(); | |
| _items = new ObservableCollection<int>(); | |
| AddItemsToCollectionView(); | |
| CollectionView.ItemsSource = _items; | |
| BindingContext = this; | |
| } | |
| public double VerticalOffset | |
| { | |
| get => _verticalOffset; | |
| set | |
| { | |
| _verticalOffset = value; | |
| OnPropertyChanged(nameof(VerticalOffset)); | |
| } | |
| } | |
| void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | |
| { | |
| VerticalOffset = e.VerticalOffset; | |
| } | |
| void EmptyButton_OnClicked(object sender, EventArgs e) | |
| { | |
| _items.Clear(); | |
| } | |
| void FillButton_OnClicked(object sender, EventArgs e) |
Copilot
AI
Dec 8, 2025
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.
Inconsistent indentation: these lines use spaces for indentation while the rest of the file uses tabs. These should be indented with tabs to match the surrounding code.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||
| using NUnit.Framework; | ||||||
| using UITest.Appium; | ||||||
| using UITest.Core; | ||||||
|
|
||||||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||||||
|
|
||||||
| public class Issue21708 : _IssuesUITest | ||||||
| { | ||||||
| public Issue21708(TestDevice device) : base(device) { } | ||||||
|
|
||||||
| public override string Issue => "CollectionView.Scrolled event offset isn't correctly reset when items change"; | ||||||
|
|
||||||
| [Test] | ||||||
| [Category(UITestCategories.CollectionView)] | ||||||
| public void VerifyCollectionViewVerticalOffset() | ||||||
|
jsuarezruiz marked this conversation as resolved.
|
||||||
| public void VerifyCollectionViewVerticalOffset() | |
| public void VerticalOffsetResetsToZeroWhenItemsAreRemoved() |
Copilot
AI
Dec 8, 2025
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.
The test only verifies the "Empty" scenario but doesn't verify the "Fill" scenario after emptying. According to the issue description, the offset should be correctly maintained when items are both added and removed. Consider adding an additional assertion after calling App.Tap("Fill") to verify that the offset updates correctly when items are re-added and the CollectionView is scrolled again.
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.
The fix sets
contentOffsetXandcontentOffsetYto 0 when there are no visible items, but thePreviousHorizontalOffsetandPreviousVerticalOffsetfields (lines 55-56) are still updated with these values. This means that when items are cleared and then re-added, the delta calculations on the next scroll will be incorrect because the previous offset won't truly be 0 if it was set to some other value before clearing. Consider also resettingPreviousHorizontalOffset = 0andPreviousVerticalOffset = 0when!visibleItemsis true to ensure proper delta calculations after items are re-added.