Reputation: 145
I have a question regarding Xamarin StackLayout and ListView.
I am using a Listview inside StackLayout. Listview contains 10 items, which will easily go beyond the stacklayout height. I have used the Orientation as Vertical
and VerticalOptions as FillAndExpand
for StackLayout. StackLayout is getting properly expand when there is no navigation title bar.
The issue is when there is Navigation title bar, Stacklayout is not expanding properly and the Listview items are getting shrinked. Any one else faces this issue?
<ContentPage.Content>
<StackLayout>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<ListView
HasUnevenRows="True"
ItemsSource="{Binding sampleList}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:sampleView/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
</ContentPage.Content>
I had tried the below mentioned options.
1) Setting the Height Request to parent Stack Layout.
It worked for some devices and not worked for some devices.
2) Use Grid instead of StackLayout by setting the Grid row definitions like given below.
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
But this change also didn't fix the issue.
3) Use Scroll View instead of StackLayout
This will work. But Xamarin suggests we should not nest ScrollView with other controls that provide scrolling, like ListView and WebView.
( https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view )
Upvotes: 1
Views: 1158
Reputation: 11
I had the same problem, to be honest I don't know the reason, but in my case I had to remove the stackLayout and left the listview into the ContentPage.
I would like to be more specific about the reason, but I've just to figure out if get more information about it I will let you know.
<ContentPage.Content>
<ListView
HasUnevenRows="True"
ItemsSource="{Binding sampleList}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:sampleView/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
Upvotes: 1