如何在ViewCell中更改高度

One*_*iva 13 c# xaml xamarin-forms

我正在尝试在listview上更改ViewCell,但下面的代码对我不起作用:

<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>
Run Code Online (Sandbox Code Playgroud)

Dan*_*rda 56

  • 如果所有单元格ListView.RowHeight在ListView本身上具有相同的大小设置属性
  • 如果你想设置ViewCell.Height而不是设置ListView.HasUnevenRowstrue(但它有一些性能影响)

  • 设置 `HasUnevenRows="true"` 才是真正的答案 (5认同)

小智 10

仅当设置或属性设置为时才设置heightfor ViewCell将起作用.ListView.HasUnevenRowsTableView.HasUnevenRowstrue


pna*_*avk 7

设置ViewCell的高度应该可以。

尝试将您的StackLayout的VerticalOptions和设置HorizontalOptionsFillAndExpand


Ant*_*ich 6

现在将2019年的正确性放在固定高度上:

<ListView RowHeight="100" />
Run Code Online (Sandbox Code Playgroud)

如果您不希望所有行都固定高度,请使用:

<ListView HasUnevenRows="true" />
Run Code Online (Sandbox Code Playgroud)