Bug 60883 - Label.TextColor no longer works for labels with FormattedText
Summary: Label.TextColor no longer works for labels with FormattedText
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
: 60953 ()
Depends on:
Reported: 2017-11-28 05:00 UTC by Kent
Modified: 2017-12-03 15:20 UTC (History)
4 users (show)

Tags: formattedtext, textcolor, ac
Is this bug a regression?: Yes
Last known good build:

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 for Bug 60883 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Kent 2017-11-28 05:00:10 UTC
Really not sure if this was intentional or not, but the behavior is inconsistent with Android and I believe broke between 2.4 and 2.5. On iOS now, setting Label.TextColor does nothing if the Label has FormattedText assigned to it. This might be the offending line, though it last changed 5 months ago: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs#L312-L313 :/
Comment 1 Kent 2017-11-28 05:08:19 UTC
Same is true of FontAttributes.
Comment 2 Paul DiPietro [MSFT] 2017-11-29 04:34:48 UTC
For the time being I will set this to confirmed; I assume there's regressed behavior as Android does work, although it should be clarified (albeit somewhat implied in the original message) that this is specifically when the TextColor value is set after the fact. For instance, doing something like this works initially:

<Label x:Name="TestLabel" TextColor="Red"
    HorizontalOptions="CenterAndExpand" >
                <Span Text="This should be red; " />
                <Span Text="and this should be blue" ForegroundColor="Blue"/>

However, changing the TextColor to green (say, via a button) doesn't change the red text in the later versions.
Comment 3 Paul DiPietro [MSFT] 2017-12-03 15:06:50 UTC
*** Bug 60953 has been marked as a duplicate of this bug. ***
Comment 4 Edward Brey 2017-12-03 15:20:52 UTC
Bug 60953, merged into this bug, broadens the scope of this bug. 60953 repros on iOS and UWP (haven't tried Android). It also repros during initial construction of the Label (doesn't require a change later, like the TextColor issue - unless using a Style effectively does that). I'm pasting the merged description below for convenience, since it's short and sweet:

If you set a Label to have a Style that sets the text size, and also set FontAttributes in a Span for the label's FormattedText, the Style's text size is ignored for that span.

var label = new Label { Style = Device.Styles.ListItemDetailTextStyle };
var text = new FormattedString();
text.Spans.Add(new Span { FontAttributes = FontAttributes.Italic, Text = "Too big" });
text.Spans.Add(new Span { Text = "Just right" });
label.FormattedText = text;