How to change height in ViewCell

I am trying to change the ViewCell in a listview, but the code below does 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> 
+10
source share
6 answers

Height adjustment for ViewCell should work.

Try setting StackLayout VerticalOptions and HorizontalOptions to FillAndExpand .

+7
source
  • If all cells are the same size, set the ListView.RowHeight property to ListView.RowHeight itself
  • If you want to set ViewCell.Height instead ViewCell.Height then set ListView.HasUnevenRows to true (but it has some performance impact).
+45
source

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

+7
source

Just set the Grid RowDefinition Height to Auto , wherever your Label is. 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> 
+3
source

The correct thing now in 2019 is to put for a fixed height:

 <ListView RowHeight="100" /> 

If you do not want to fix the height in all lines, use:

 <ListView HasUnevenRows="true" /> 
0
source

Height / Weight properties are mostly read-only in Xamarin. You cannot set the size of the ViewCell.

However, you can change the StackLayout HeightRequest property to achieve what you want.

-2
source

All Articles