CollectionView not scrolling inside a StackLayout or without setting HeightRequest
See original GitHub issueDescription
If the items inside an ObservableCollection are too many for a CollectionView to display, they can’t be scrolled if the CollectionView is inside a StackLayout.
Steps to Reproduce
- Create a new MAUI project;
- Add a StackLayout and inside a CollectionView;
- Bind the ItemSource of the CollectionView to a property in the MVVM with many items;
- Voilà, you now can’t scroll the CollectionView. But if you change the StackLayout into a Grid, or if you add a HeightRequest to the CollectionView (voilà again) you now can scroll it.
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12
Did you find any workaround?
The only way to scroll them is set the HeightRequest property to the CollectionView or change the StackLayout into a Grid.
Thats the buggy code:
<StackLayout> <CollectionView ItemsSource="{Binding Monkeys}"> <CollectionView.ItemTemplate> <DataTemplate> <Label Text="{Binding Title}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </StackLayout>
But if you add the HeightRequest property to the CollectionView it works fine:
<StackLayout> <CollectionView ItemsSource="{Binding Monkeys}" HeightRequest="200" > <CollectionView.ItemTemplate> <DataTemplate> <Label Text="{Binding Title}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </StackLayout>
And if you add change the StackLayout into a Grid it still works fine:
<Grid> <CollectionView ItemsSource="{Binding Monkeys}"> <CollectionView.ItemTemplate> <DataTemplate> <Label Text="{Binding Title}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </Grid>
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:16 (1 by maintainers)
Top Related StackOverflow Question
@rmarinho closed this as “that’s not a bug, it’s the way it should be”. But since we have found that a CollectionView in a Grid with the RowDefinition / ColumnDefiniton property does not work as it should, I think this could be a bug.
Also, maybe this issue is closed because it’s one of many duplicates 😃 I opened mine on June 15th and it’s still open https://github.com/dotnet/maui/issues/8097