question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested Stacklayouts inner Stacklayout only renders height of first element (.NET 7.0)

See original GitHub issue

Description

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>

image

Steps to Reproduce

  1. Create a File .NET new MAUI project
  2. Create a Listview bound to a dataset
  3. 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:open
  • Created 10 months ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ooikengsiangcommented, Dec 4, 2022

The workaround currently are

  • Fixed RowHeight
  • HasUnevenRows=“True”
0reactions
homeyfcommented, Jun 6, 2023

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 image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Summary
Nested Stacklayouts inner Stacklayout only renders height of first element (.NET 7.0) #17471. Sign in to view logs · Sign in to view...
Read more >
Workflow file for this run
NET Multi-platform App UI, a framework for building native device ... Nested Stacklayouts inner Stacklayout only renders height of first element (.NET 7.0) ......
Read more >
Layouts - .NET MAUI
A StackLayout organizes elements in a one-dimensional stack, either horizontally or vertically. The Orientation property specifies the ...
Read more >
Xamarin Forms StackLayout: How to set width / height of ...
StackLayout doesn't go very well with varying heights in this scenario. ... can expand to the full width or height of its parent...
Read more >
Learn Live - Customize layout in .NET MAUI XAML pages
44:24 - How to add views to a StackLayout 46:15 - How to change ... Learning objectives - Arrange user interface elements in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found