6

Xamarin.Forms ListView has some tendency to stop stretching after some maximal height. When I put too many items in ListView, it creates scrollbar and height of it doesn't increase while I'm adding more of them.

It could be confusing to user if <ListView> with scrollbar is inside <ScrollView> object that has scrollbar too. Layout bahaves unnaturally, forcing user to scroll to the end of listview to be able to continue scrolling scrollView.

So, summing up:

How can I disable scrollbar in ListView, forcing it to have the height of all its interior children?

Children don't have equal heights. Also, they can change during app lifetime.

<ScrollView>
    <StackLayout>
        <!-- some buttons and labels -->
        <ListView ItemsSource="{Binding Data}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="20">
                            <!-- Some information -->
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ScrollView>

Platform on which I test my app: Windows 10 UWP.

10
  • Are you using ScrollView with ListView inside of it? Commented Jun 26, 2016 at 14:27
  • @jzeferino yes, I am Commented Jun 26, 2016 at 14:39
  • Isn't recommended to do that. Normally if you want that you should use footer and header of the listview. Commented Jun 26, 2016 at 14:41
  • Are there any other ways to use data binding from c# List<>? It's not necessary for me to use ListView. I just need to loop for each object in List and view its data. Commented Jun 26, 2016 at 14:51
  • 1
    if you want to display a list of items use a RepeaterView like this one forums.xamarin.com/discussion/21635/… Commented Jun 26, 2016 at 22:06

3 Answers 3

14

I also face the same problem,I solved it by using Bindable StackLayout inside Scroll View.

<ScrollView>
    <StackLayout BindableLayout.ItemsSource="{Binding ItemSource}">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                 <Label Text="{Binding Name}" />
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>
</ScrollView>
Sign up to request clarification or add additional context in comments.

2 Comments

Can the BindableLayout be bound with a any list of any type of object like the ListView?
Yes you can bind any type of object
8

Listview already has an inbuilt scroll mechanism, you should never try to put ListView inside ScrollView.

ListView uses UI Virtualization, which means, it will only create required items in the visible view, and not all the items. For example, if you load 240 countries, it will only actually create 20 countries and as you scroll, it will create more or reuse existing items.

By putting ListView inside ScrollView, you will disable UI virtualization.

Infact, Xamarin.Forms does not do anything special for scrolling, it is feature of underlying platform Android/iOS/Windows that provide UI virtualization to improve speed.

Comments

0

I have the same problem, wherein I have a CollectionView which lists a bunch of records. Each record may have one or more child elements that I need to display without scrolling.

I solved it by setting the inner ListView scroll property and adding a box view on top of it so users cannot scroll the list.

<Grid>
     <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />
     </Grid.ColumnDefinitions>
     <Grid.RowDefinitions>
       <RowDefinition Height="Auto" />
     </Grid.RowDefinitions>
  <!-- inner list view -->
  <ListView Grid.Row="0" Grid.Column="0" VerticalScrollBarVisibility="Never" SelectionMode="None">
   <!-- content here -->
  </ListView>
  <BoxView Grid.Row="0" Grid.Column="0" />
</Grid>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.