How Can I Change Height in ViewCell

30.5k views Asked by At

I'm trying to change ViewCell on listview, but the code below not work for me:

<DataTemplate>
    <ViewCell Height="100">
        <StackLayout Orientation="Horizontal">
            <Image Source="{Binding Seller.Thumbnail}}" Aspect="AspectFit" />
            <StackLayout Orientation="Vertical" >
                <Label Text="{Binding CouponName}" FontAttributes="Bold" FontSize="12" />
                <Label Text="{Binding EndOffer}" FontSize="11" />
            </StackLayout>
        </StackLayout>
    </ViewCell>
</DataTemplate>
6

There are 6 answers

1
pnavk On BEST ANSWER

Setting the height for the ViewCell should work.

Try setting your StackLayout's VerticalOptions and HorizontalOptions to FillAndExpand.

1
Burak Kaan Köse On

Height / Weight properties are mostly read-only in Xamarin.You can't set size of ViewCell.

However , you can change your StackLayout's HeightRequest property to achieve what you want.

1
Akash Singh On

Setting the height for the ViewCell will work only if ListView.HasUnevenRows or TableView.HasUnevenRows property set to true.

1
Benjamín Romero On

Just set Grid's RowDefinition's Height to Auto, wherever your Label it's wrapped. Like this:

<ListView ItemsSource="{Binding Gastos}" HasUnevenRows="True" SeparatorVisibility="None">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell >
                <Grid Padding="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Label Text="{Binding Id}" VerticalOptions="Start"/>
                    <Label Grid.Column="1" Text="{Binding Descripcion}" LineBreakMode="WordWrap"/>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
1
Daniel Luberda On
  • If all cells have the same size set ListView.RowHeight property on ListView itself
  • If you want to set ViewCell.Height instead then set ListView.HasUnevenRows to true (but it has some performance impact)
0
Anton Nikolayevich On

The correct now in 2019 is put this for fix height:

<ListView RowHeight="100" />

If yout don't want fix height in all rows, use:

<ListView HasUnevenRows="true" />