How to set ListView Row Height in Xamarin.Forms
19,134
Solution 1
On iOS
, when you set ListView.HasUnevenRows
to true
, you also have to set the Cell.Height
for each cell property too, as the renderer can not infer it from the content.
You can also use ListView.RowHeight
like you do in your example, for even rows. In that case, do not set ListView.HasUnevenRows
(or set it to false
).
Solution 2
Try using a StackLayout instead of a ListView:
<StackLayout BindableLayout.ItemsSource="{Binding Items}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Margin="0,0,0,5">
<Label Text="{Binding Name}"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
Comments
-
Nirav Mehta almost 2 years
I want to set height of the
ListView
in XAML file for iOS Device using below mentioned code and bindings.- I've used observable collection to notify when the property value is updated and it is getting notified and sets the correct value but it is not being reflected in iOS Simulator or device but that works fine with Android & Windows Phone Devices.
<ListView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding QuestionAnswerList,Mode=TwoWay}" SelectedItem="{Binding SelectedData,Mode=TwoWay}" HasUnevenRows="true" RowHeight="{Binding Custom_height,Mode=TwoWay}" BackgroundColor="Silver" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <ListView.ItemTemplate>
I've tried to set Row Height of List View statically as well but that also doesn't work.
I haven't given any height and set Grid RowDefinition height = "*" but then also it doesn't set the height of the ListView instead it overlaps the details on the next ListView row.
Thanks.
-
quemeful about 3 yearsI have spent days searching for this. A way to make a list without being stuck with the annoying default system list. Thank you so much.