【问题标题】:Xamarin.Forms Vertical StackLayout in ListView displays only one (first) ChildListView 中的 Xamarin.Forms Vertical StackLayout 仅显示一个(第一个)子级
【发布时间】:2015-05-11 09:04:24
【问题描述】:
<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。 StackLayout 包含两个Labels(“消息”和“发件人”已绑定到其中),当前仅显示一个孩子。使用上面的代码,它只显示“消息”。如果我将代码更改为

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

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

【问题讨论】:

  • 看来您将列表视图放在网格中,您可以尝试将列表视图放在网格之外吗?
  • 也可能是第二个孩子没有显示,因为行高太小,被截断了。尝试设置 ListView 的 RowHeight 属性。

标签: xaml xamarin xamarin.forms


【解决方案1】:

问题与@Grisha 指出的类似。事实证明 RowHeight 更小,第二个 StackLayout 被剪掉了。

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

【讨论】:

  • 谢谢,这对我有帮助。
猜你喜欢
  • 2023-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-03
  • 2020-06-10
  • 2019-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多