3
votes

Ive been trying to sort out issues with the Row Height that gets calculated when rendering a ListView in Xamarin Forms (iOS)

Here is my XAML

<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <Grid Padding="20">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackLayout Orientation="Vertical" Grid.Row="0">
                    <Label Text="{Binding Path=Name}" FontSize="18" />
                    <Label Text="{Binding Path=Teaser}" TextColor="Gray" />
                </StackLayout>
                <StackLayout Grid.Column="1" Grid.Row="0">
                    <Image Source="{Binding Path=ImageUrl}" WidthRequest="100" Aspect="AspectFill"
                           HeightRequest="100" />
                </StackLayout>
            </Grid>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>

but here is a screenshot of how it gets rendered in the simulator

(I am binding to 10 rows of the same data, which is why each row looks the same)

enter image description here

As you can see, the row height isnt being correctly calculated for the row contents.

I can set a fixed RowHeight for the ListView but this isnt good because the rowheight will need to be different for different devices.

Can anyone help ?

1
set your_list.HasUnevenRows = true; and your_list.RowHeight = 60;Pucho Eric
ah thanks so much. The HasUnevenRows=true fixed it (i assumed you only set it to true if the rows were uneven). I didnt set the row height as it needs to be different depending on the size of the deviceDean Chalk
Okay, i'll post as answerPucho Eric

1 Answers

7
votes

Set

your_list.HasUnevenRows = true; 

and/or

your_list.RowHeight = 60;