How Can I Change Height in ViewCell
26,426
Solution 1
Setting the height for the ViewCell should work.
Try setting your StackLayout's VerticalOptions
and HorizontalOptions
to FillAndExpand
.
Solution 2
- If all cells have the same size set
ListView.RowHeight
property on ListView itself - If you want to set
ViewCell.Height
instead then setListView.HasUnevenRows
totrue
(but it has some performance impact)
Solution 3
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" />
Solution 4
Setting the height
for the ViewCell
will work only if ListView.HasUnevenRows
or TableView.HasUnevenRows
property set to true
.
Solution 5
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>
![One Brasil Mídia Interativa](https://lh6.googleusercontent.com/-n2I_mIgBXh8/AAAAAAAAAAI/AAAAAAAAACs/N-W3TSWuP6E/photo.jpg?sz=256)
Author by
One Brasil Mídia Interativa
Updated on August 08, 2022Comments
-
One Brasil Mídia Interativa almost 2 years
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>
-
Clint StLaurent almost 8 years"generally" being the key term here. In the case of ViewCell however it is get/set. If you look at the intellisense that pops up on that property in Visual Studio this is confirmed. You do have to keep in mind that the RowHeight of the ListView itself will take precedence. So setting the .Height of a CellView can appear to to not have any affect. It is primarily meant to be used in conjunction with
ListVIew.HasUnevenRows=true
-
ToolmakerSteve about 6 yearsSee Daniel Luberda's answer, for discussion of ListView.RowHeight vs ViewCell.Height.
-
ToolmakerSteve about 6 yearsImportant: This answer is for labels that may WordWrap to multiple lines of text. If doing so, don't forget HasUnevenRows="True", as seen in the code snippet above.
-
ToolmakerSteve about 6 yearsTrue, but see Daniel Luberda's more complete answer above, which already said this.
-
derekantrican over 4 yearsSetting
HasUnevenRows="true"
is the real answer here