如何在ViewCell中更改高度

时间:2015-06-07 17:24:55

标签: c# xaml xamarin-forms

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

CGRect r1 = [[[signature.rawPoints objectAtIndex:i]objectAtIndex:j] CGRectValue]; 

6 个答案:

答案 0 :(得分:45)

  • 如果所有单元格都具有相同的大小设置ListView.RowHeight属性 ListView本身
  • 如果您想设置ViewCell.Height 然后将ListView.HasUnevenRows设置为true(但会产生一些性能影响)

答案 1 :(得分:7)

设置ViewCell的高度应该有效。

尝试将StackLayout的VerticalOptionsHorizontalOptions设置为FillAndExpand

答案 2 :(得分:7)

仅当heightViewCell属性设置为ListView.HasUnevenRows时,设置TableView.HasUnevenRows的{​​{1}}才有效。

答案 3 :(得分:3)

只需将Grid的 RowDefinition 高度设置为 自动 ,无论您的标签包装在哪里。像这样:

<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>

答案 4 :(得分:0)

现在将2019年的正确高度设为固定高度:

<ListView RowHeight="100" />

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

<ListView HasUnevenRows="true" />

答案 5 :(得分:-2)

高度/重量属性在Xamarin中大多是只读的。您无法设置ViewCell的大小。

但是,您可以更改StackLayout的HeightRequest属性以达到您想要的效果。

相关问题