Label doesn't render correctly when in a Grid with column definitions
See original GitHub issueDescription
- Label that is set with the end trailing doesn’t display the trailing dots (…)
- Label that is set with MaxLines=“3” doesn’t always display the 2nd and 3rd lines when in a grid (there is a situation when the 3 lines are rendered but the grid size expands only to the first line and the 2nd and 3rd lines are visible outside of the grid).
Steps to Reproduce
This example would display only two lines. One from row 1 and another from row 2. What is expected is to see more than one lines in the 2nd row. (Look for a picture in the comments bellow.)
<Grid
RowDefinitions="auto,auto"
ColumnDefinitions="auto,*,auto"
BackgroundColor="LightBlue"
VerticalOptions="Start"
>
<!-- first line -->
<Label
Margin="0,16,0,0"
VerticalOptions="Start"
HorizontalOptions="Start"
Grid.Row="0"
LineBreakMode="TailTruncation"
Text="s{Binding CustomerName} HHHHHHHHH HHHHHHHHH HHHHHHHHHHH HHHHHHHHHHH"
FontSize="16"
/>
<!-- second line -->
<Label
Grid.Row="1"
Margin="0,0,16,16"
VerticalOptions="Start"
HorizontalOptions="Start"
LineBreakMode="WordWrap"
Text="x{Binding Notes}xxxxxxxx OO xxxxxxxxxxxHHHHH xxxxxxxxxxxx xxxxxxxxxxxxx xxxxxx xxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxxx xxxxxx 333333333333333333333"
MaxLines="3"
LineHeight="1"
FontSize="12"
BackgroundColor="Yellow"
/>
</Grid>
Link to public reproduction project repository
none, example provided in the description
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 15.4
Did you find any workaround?
if the columns definitions are removed it would render correctly. In real scenario the columns are needed and can’t be removed.
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:8
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Label takes extra height when inside a grid with many ...
In Xamarin Forms, when I put a label inside a grid with many columns, the label takes extra height just as if the...
Read more >JavaScript Data Grid: Updating Column Definitions
It is possible to add and remove columns by updating the list of Column Definitions provided to the grid. When new columns are...
Read more >Preventing a Grid Blowout
In our simple demo, the <main> element automatically places itself in that first column as it is the first child of the grid....
Read more >Data Grid - Column definition
By default, the data grid uses the field of a column to get its value. For instance, the column with field name will...
Read more >Xamarin.Forms Grid
The Xamarin.Forms Grid is a layout that organizes its children into rows and columns of cells.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The fact that the text does not wrap in the second Label is not a bug, it’s as designed. The Label is in column with a
WidthofAuto; this means that each item in the column is measured as if it had infinite width available. Given infinite width, the Label has no reason to wrap its text, and simply lays it out in a single line that runs off the edge of the Grid. The other two columns are empty, so they have no effect on the layout at all.If you want the Label to wrap at the edge of the Grid, you should set the
ColumnDefinitionsto*.For the Label with
LineBreakModeset toTailTruncation, it looks like we do have a bug; even with the columns set to*, it won’t truncate properly. It looks like the issue is related to havingHorizontalOptions="Start". As a workaround until we can fix it, you can set theHorizontalOptionsfor that Label toFilland the text will truncate as expected.Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Windows 11, Android 13.0-API33 and iOS 16.4 with provided project: 10494.zip