Nested Stacklayouts inner Stacklayout only renders height of first element (.NET 7.0)
See original GitHub issueDescription
When using a listview with nested stacklayouts in a DataTemplate’s ViewCell, the Stacklayout seems to only size itself to the first element in the listview. This leads to incorrect height calculation for the parent items.
Example XAML construct (Background colors have been applied to the parent StackLayout and the child stacklayout (purple for parent, Green for inner stacklayout).
Expected behavior: The Green inner layout should color both the player’s name and their location / city. Actual behavior: Green only encompasses the size of the First item in the stacklayout, showing its size is calculated wrong given its contents.
<ListView x:Name="PlayersListView"
ItemsSource="{Binding Players}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" BackgroundColor="Purple">
<Label Margin="10,0" VerticalTextAlignment="Center" Text="{Binding CurrentWpprRank}"
LineBreakMode="NoWrap"
FontSize="24" MinimumWidthRequest="58" HorizontalOptions="Start" />
<StackLayout Margin="10" Orientation="Vertical" HorizontalOptions="FillAndExpand" BackgroundColor="Green" >
<Label LineBreakMode="NoWrap" FontSize="16">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="{Binding FirstName}" />
<Span Text=" " />
<Span Text="{Binding LastName}" />
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<StackLayout Orientation="Horizontal">
<Label TextColor="{DynamicResource SecondaryTextColor}" Text="{Binding City}" HorizontalOptions="StartAndExpand" LineBreakMode="NoWrap" FontSize="12" />
<Label TextColor="{DynamicResource SecondaryTextColor}" HorizontalOptions="End" Text="{Binding WpprPoints, StringFormat='{0:N2}'}" LineBreakMode="NoWrap"
FontSize="10" />
</StackLayout>
<Label HorizontalOptions="StartAndExpand" LineBreakMode="NoWrap" TextColor="{DynamicResource SecondaryTextColor}"
FontSize="10" HorizontalTextAlignment="Start" IsVisible="{Binding Source={x:Reference BrowseItemsPage}, Path=BindingContext.ShowOverallRank}">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="Overall WPPR Rank:" />
<Span Text=" " />
<Span Text="{Binding CurrentWpprRank, Converter={StaticResource intToOrdinalString}}" />
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Steps to Reproduce
- Create a File .NET new MAUI project
- Create a Listview bound to a dataset
- Set the ViewCell template to Contain markup as described in the description part of this ticket
Link to public reproduction project repository
https://github.com/edgiardina/MAUI-StackLayout-HeightCalc-Bug
Version with bug
7.0 Release Candidate 2
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
iOS 16, Android
Did you find any workaround?
No response
Relevant log output
No response
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:5 (1 by maintainers)

Top Related StackOverflow Question
The workaround currently are
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on Android platform with sample project. https://github.com/edgiardina/MAUI-StackLayout-HeightCalc-Bug