-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
When I use Label.FormattedText (e.g. to format a string with a localization resource as below), certain style attributes like FontAttributes="Bold"or TextColor="MediumPurple" are ignored when they are used directly on the Label:
<Label FontSize="16" FontAttributes="Bold" TextColor="MediumPurple" Margin="8, 10, 0, 0">
<Label.FormattedText>
<FormattedString >
<Span Text="{loc:Translate SelectItem_LabelHeading}"
<Span Text=": " />
</FormattedString>
</Label.FormattedText>
</Label>When they are set on each Span element, e.g. with a style, they are applied, but then an attribute like `FontSize="25" is not applied anymore:
<ContentPage.Resources>
<ResourceDictionary>
...
<Style x:Key="HeaderLabelStyle" TargetType="Label">
<Setter Property="FontSize" Value="16"/>
<Setter Property="TextColor" Value="MediumPurple"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>...
<Label FontSize="25" Margin="8, 10, 0, 0">
<Label.FormattedText>
<FormattedString >
<!-- Style has to be applied like this on each Span element, otherwise it will be ignored. -->
<Span Text="Select a value" Style="{StaticResource HeaderLabelStyle}" />
<Span Text=": " Style="{StaticResource HeaderLabelStyle}" />
</FormattedString>
</Label.FormattedText>
</Label>
...I don't know if this is the intended behavior, but at least from my perspective attributes should be accumulative from top to bottom. So all child elements „inherit“ all the Attributes from their parent first (top to bottom). If a child also sets the same attribute, it should be overwritten for that specific element then.
Therefore, in the snippet above with FontSize="16", all the attributes set on the Label should also be set in the child and therefore be applied to the Span elements.
Steps to Reproduce
- Use the attached reproducible example in
MainPage.xaml - Define style attributes like
FontAttributes="Bold"orTextColor="MediumPurple"on theLabelwith theLabel.FormattedText - See that in this example, an attribute like
FontSize="16"is still applied, but other attributes likeFontAttributes="Bold"orTextColor="MediumPurple"are ignored on the<Span Text="Select a value" />and<Span Text=": " />elements - When styles are applied like in the
<Span Text="Select a value" Style="{StaticResource HeaderLabelStyle}" />and<Span Text=": " Style="{StaticResource HeaderLabelStyle}" />elements, the style attributesFontAttributes="Bold"orTextColor="MediumPurple"are applied, but then a hugeFontSize="25"defined on theLabelis ignored
Expected behavior is that in both examples all style attributes should be accumulative and applied down to the child Span elements
Link to public reproduction project repository
FormattedLabelTextIgnoresAttributes_27828
Version with bug
9.0.40 SR4
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
No response
Did you find any workaround?
No response

