xaml - ListView 中的 Xamarin.Forms Vertical StackLayout 仅显示一个(第一个)子级

标签 xaml xamarin xamarin.forms

<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其中包含两个 Label s(已绑定(bind)“Message”和“Sender”),当前仅显示一个 child 。使用上面的代码,它只显示“消息”。如果我将代码更改为
<StackLayout
      BackgroundColor="Gray"
      Orientation="Vertical"
      VerticalOptions="Center">
      <Label
         Text="{Binding Sender}"
         XAlign="Start"
         TextColor="Red"/>
      <Label
          Text="{Binding Message}"
          XAlign="Start"/>
  </StackLayout>

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

最佳答案

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

解决方案是设置 HasUnevenRows ListView 的属性(property)成为 TRUE .因此,RowHeight是自动计算的。

关于xaml - ListView 中的 Xamarin.Forms Vertical StackLayout 仅显示一个(第一个)子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30163537/

相关文章:

wpf - 如何将样式传播到 DataTemplate 内的超链接?

wpf - 将子项与主项一起绑定(bind)到同一控件 WPF

xaml - ContentDialog 的大小不适合具有大 TextBlock 的通用应用程序中的内容

c# - Xamarin.iOS 状态栏在更改其文本颜色时消失

ios - IBOutletCollection 与 Xamarin 可能吗?

ios - (Xamarin iOS) : ExecutionEngineException - Attempting to JIT compile method while running in aot-only mode

xaml - 如何在 Xamarin Forms 中超链接部分标签文本?

c# - 我可以强制 .NET XmlDocument 实例尽快释放它占用的内存吗?

c# - Xam.Plugin.Connectivity(作者 James Montemagno)无视提供的超时

c# - 从我的Apk大小如何知道上传之前我的应用程序的下载大小?