Xamarin.Forms Vertical StackLayout in ListView displays only one (first) child

<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>

      

I am creating a custom ListView in a Xamarin.Forms app. StackLayout

which contains two Label

(to which "Message" and "Sender" are attached), currently only one child is displayed. With the above code, only "Message" is displayed. If I change the code

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

      

only the sender is displayed. In short, it only displays the first child. What did I do wrong here?

+3


source to share


1 answer


The problem was similar to what @Grisha pointed out. The RowHeight is smaller, and the second StackLayout is clipped.



The solution was to set the HasUnevenRows

property ListView

as TRUE

. Thus, it RowHeight

was calculated automatically.

+8


source







All Articles