AutoHeight in CollectionView inside a ScrollView page in Xamarin, is it possible?

Newbie Dev 1 Reputation point
2021-10-14T17:14:48.81+00:00

Hello all,
I have a CollectionView inside a StackLayout in a ScrollView Page.

The current way it works is: CollectionView is scrollable and cropped(I need to set its height manually which won't update itself automatically even if VerticalOptions are FillAndExpand or whatever)

What I want instead is to show all items in the list until they're finished and keeping the page scrollable(if there's any other content under the collectionview ofcourse)
I don't know if the problem is related to the ScrollView, but as I said above I also tried setting verticaloptions.

Code sample:
<ContentPage ...>
<ScrollView>
<StackLayout>

 <CollectionView ...>
 </CollectionView>

</StackLayout>
</ScrollView>
</ContentPage>

Thanks in advance for help

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,936 Reputation points
    2021-10-15T06:39:52.357+00:00

    Hello @Newbie Dev ,​

    Welcome to our Microsoft Q&A platform!

    It's not recommended to use a CollectionView inside a ScollView, which may cause some scrolling issues. To display the collection items, try using BindableLayout instead. BindableLayout class provides ItemsSource and ItemTemplate properties that could help display the data.

       <ScrollView>  
           <StackLayout x:Name="parentLayout">  
         
               <StackLayout BindableLayout.ItemsSource="{Binding DataCollection}">  
                   <BindableLayout.ItemTemplate>  
                       <DataTemplate>  
                           <!--the item content-->  
                       </DataTemplate>  
                   </BindableLayout.ItemTemplate>  
               </StackLayout>  
                 
               <!--other content-->  
           </StackLayout>  
       </ScrollView>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.