Bug 44483 - Label ignores HorizontalTextAlignment when truncating Text
Summary: Label ignores HorizontalTextAlignment when truncating Text
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-09-19 09:25 UTC by Falko Schindler
Modified: 2017-01-25 10:15 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Screenshot of the posted example page (51.01 KB, image/png)
2016-09-19 09:27 UTC, Falko Schindler

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Falko Schindler 2016-09-19 09:25:51 UTC
A Label with HeadTruncation ignores its HorizontalOptions set to EndAndExpand as soon as the Text is long enough for the truncation to be applied.

I created the following example comparing the behavior for two identical labels except for their text length. Although the longer label gets truncated due to its Text being to long for the screen, there is some space left after applying the truncation. This space should stay outside of the label on the left-hand side (white) and not within the label on its right-hand side (green) as it is at the moment.

    MainPage = new ContentPage {
        Content = new StackLayout {
            VerticalOptions = LayoutOptions.Center,
            Children = {
                new Label {
                    BackgroundColor = Color.Lime,
                    Text = "This is some random test text.",
                    HorizontalOptions = LayoutOptions.EndAndExpand,
                    LineBreakMode = LineBreakMode.HeadTruncation,
                new Label {
                    BackgroundColor = Color.Lime,
                    Text = "Welcome to Xamarin Forms! This is some random test text.",
                    HorizontalOptions = LayoutOptions.EndAndExpand,
                    LineBreakMode = LineBreakMode.HeadTruncation,

The error occurs on iOS and Android at least since Xamarin.Forms 2.0.1.
Comment 1 Falko Schindler 2016-09-19 09:27:52 UTC
Created attachment 17580 [details]
Screenshot of the posted example page

Like the first label, the longer label should have no space at the end. The green background should be slightly smaller than the page and right-aligned.
Comment 2 Stephane Delcroix 2016-10-04 09:30:10 UTC
`HorizontalOptions` sets the way the Label control (the green block) is drawn inside it's parent.

In both cases, the Label control correctly follows the "EndAndExpand" as it's flushed right.

You are looking about how the text is aligned _within_ the Label control. The option you are looking for is HorizontalTextAlignment = TextAlignment.End.

That fixes it.
Comment 3 Falko Schindler 2016-10-04 09:41:06 UTC

As far as I understand, EndAndExpand should not let the label (=the green box) *fill* the whole space, but only occupy it.
In contrast, with FillAndExpand I would expect to see a green box with maximum width due to the property "Fill". Expand alone should not affect its size.
Comment 4 Rui Marinho 2017-01-04 17:05:39 UTC
Stephane Delcroix is right, the usage is as expected. This is not a issue.
Comment 5 Falko Schindler 2017-01-25 10:15:07 UTC
Ah, I think I understood. As I understand, the layout process is as follows:

1. The second label text is pretty long. So the label (green box) happens to become as wide as the containing page.
2. The truncation shortens the text and inserts "...". The width of the label is *not* affected.
3. Only now the shortened text is placed inside the green label. Since the text alignment is `Start` by default, we see a tiny space at the end.