如何在Xamarin.Forms中设置ListView行高

Nir*_*hta 7 iphone ipad ios xamarin xamarin.forms

我想使用下面提到的代码和绑定在iOS设备的XAML文件中设置ListView的高度.

1)我已经使用了可观察的集合来通知属性值何时更新并且它被通知并设置正确的值,但它没有反映在iOS模拟器或设备中,但适用于Android和Windows Phone设备.

<ListView  Grid.Row="2" Grid.Column="1"  ItemsSource="{Binding QuestionAnswerList,Mode=TwoWay}"  SelectedItem="{Binding SelectedData,Mode=TwoWay}"                   
                 HasUnevenRows="true" RowHeight="{Binding Custom_height,Mode=TwoWay}"  BackgroundColor="Silver" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
    <ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

2)我试图静态地设置列表视图的行高,但这也不起作用.

3)我没有给出任何高度并设置Grid RowDefinition height ="*"但是它也没有设置ListView的高度,而是重叠下一个ListView行的细节.

谢谢.

Ste*_*oix 15

iOS,当你设置ListView.HasUnevenRowstrue,你也必须设置Cell.Height 为每个小区物业也一样,渲染器不能从内容推断它.

您也可以ListView.RowHeight像在示例中一样使用偶数行.在这种情况下,请勿设置ListView.HasUnevenRows(或将其设置为false).


小智 8

尝试使用 StackLayout 而不是 ListView:

<StackLayout BindableLayout.ItemsSource="{Binding Items}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <StackLayout Margin="0,0,0,5">
                <Label Text="{Binding Name}"/>
            </StackLayout>
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)