question

NewbieDev-7585 avatar image
0 Votes"
NewbieDev-7585 asked JarvanZhang-MSFT edited

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

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

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello @NewbieDev-7585 ,​

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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @NewbieDev-7585
May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.

0 Votes 0 ·