【发布时间】: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