Dean Chalk
Dean Chalk

Reputation: 20481

Xamarin Forms ListView Row Height Incorrect

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 ?

Upvotes: 3

Views: 2972

Answers (1)

Pucho Eric
Pucho Eric

Reputation: 505

Set

your_list.HasUnevenRows = true; 

and/or

your_list.RowHeight = 60; 

Upvotes: 7

Related Questions