xamarin.forms在listView中的垂直堆栈仅显示一个(第一个)孩子


<ListView 
    ItemsSource="{Binding Messages}"
    Grid.ColumnSpan="2"
    HeightRequest="100">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout>
                        <Label
                            Text="{Binding When}"
                            XAlign="Center"/>
                        <StackLayout
                            BackgroundColor="Gray"
                            Orientation="Vertical"
                            VerticalOptions="Center">
                            <Label
                                Text="{Binding Message}"
                                XAlign="Start"/>
                            <Label
                                Text="{Binding Sender}"
                                XAlign="Start"
                                TextColor="Red"/>
                        </StackLayout>
                    </StackLayout>
                 </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我正在xamarin.forms应用程序中渲染自定义listView。包含两个Label S的StackLayout("消息"one_answers"发送者"已绑定),目前仅显示一个孩子。使用上面的代码,它仅显示"消息"。如果我将代码更改为

<StackLayout
      BackgroundColor="Gray"
      Orientation="Vertical"
      VerticalOptions="Center">
      <Label
         Text="{Binding Sender}"
         XAlign="Start"
         TextColor="Red"/>
      <Label
          Text="{Binding Message}"
          XAlign="Start"/>
  </StackLayout>

它仅显示发件人。简而言之,它仅显示第一个孩子。我在这里做错了什么?

问题类似于@grisha指出的问题。Rowheight被证明是较少的,第二个堆栈被剪裁了。

解决方案是将ListViewHasUnevenRows属性设置为TRUE。因此,自动计算RowHeight

最新更新