Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms: ListView inside StackLayout: How to set height?

In a ContentPage I have a ListView inside a StackLayout inside a ScrollView. The ListView is populated (ItemSource is set) in the ContentPage when OnAppearing gets called and I can see that the list is populated in the emulator. The StackLayouts orientation is Vertical and below the ListView I have a Button.

My problem is that no matter how many elements the ListView has, it gets the height of 53.33. I would like the height of the ListView to match the total height of the items in it. By setting HeightRequest I can set the height of the ListView to anything I want, but since I do not know the height of the items inside the ListView the result is most often that the distance to the button below it is incorrect and therefore looks ugly. I have tried to set VerticalOptions on both the ListView and the StackLayout to Startand other settings, but this does not change the height from 53.33 (and if I try to combine using HeightRequest and Start it turns out that HeightRequest wins out).

How can I solve this?

(please excuse the cross posting from Xamarin forum)

like image 225
Halvard Avatar asked Jul 06 '14 17:07

Halvard


Video Answer


1 Answers

With the new BindableLayout feature in Xamarin Forms 3.5 you can easily use the ItemsSource on StackPanel.

So, basically you can write something like this:

<StackLayout BindableLayout.ItemsSource="{Binding list}">     <BindableLayout.ItemTemplate>         <DataTemplate>             ...         </DataTemplate>     </BindableLayout.ItemTemplate> </StackLayout> 

You can read more about it here: https://blog.xamarin.com/xamarin-forms-3-5-a-little-bindable-love/

like image 141
mehrandvd Avatar answered Sep 20 '22 02:09

mehrandvd