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 set ListView.HasUnevenRows to true (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>
Share:
26,426
One Brasil Mídia Interativa
Author by

One Brasil Mídia Interativa

Updated on August 08, 2022

Comments

  • One Brasil Mídia Interativa
    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
    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
    ToolmakerSteve about 6 years
    See Daniel Luberda's answer, for discussion of ListView.RowHeight vs ViewCell.Height.
  • ToolmakerSteve
    ToolmakerSteve about 6 years
    Important: 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
    ToolmakerSteve about 6 years
    True, but see Daniel Luberda's more complete answer above, which already said this.
  • derekantrican
    derekantrican over 4 years
    Setting HasUnevenRows="true" is the real answer here