CollectionView not scrolling inside a StackLayout or without setting HeightRequest

See original GitHub issue

Description

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

  1. Create a new MAUI project;
  2. Add a StackLayout and inside a CollectionView;
  3. Bind the ItemSource of the CollectionView to a property in the MVVM with many items;
  4. 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:closed
  • Created a year ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
justcivahcommented, Jul 26, 2022

@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.

0reactions
imsam67commented, Jul 26, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

CollectionView is not scrolling without setting the height ...
Only one of the StackLayouts is displayed when the Page is Appearing. So, if I set the height of the second row to...
Read more >
CollectionView can't scroll ? - Microsoft Q&A
This is a known issue in MAUI:CollectionView not scrolling inside a StackLayout or without setting HeightRequest . Here is a workaround, you ...
Read more >
CollectionView inside ScrollView - Luis Matos
Learn how to use the CollectionView within a ScrollView in Xamarin. ... the ScrollView does not scroll unless you scroll from the header ......
Read more >
I've had it : r/dotnetMAUI
A CollectionView inside of a VerticalStackLayout may be part of this issue. the VStack is simplistic and will not size/distribute children, ...
Read more >
.NET MAUI: Let's Play with CollectionView Layouts
In this blog post we will play and see what layout features CollectionView is providing to .NET MAUI developers. CollectionView is a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found