Skip to content

Label FormattedString not reacting to AppThemeBinding change at runtime #17938

Closed

Description

@davidortinau

Description

When changing the theme at runtime on Android or iOS, the implicit TextColor on a Label style is not being respected. Restarting the app is accurate. I tried .NET 8 RC2 and .NET 7 - 7.0.96.

<Label 
    SemanticProperties.HeadingLevel="Level2">
    <Label.FormattedText>
        <FormattedString>
            <Span Text=".NET MAUI uses the latest technologies for building native apps on Windows, macOS, iOS, and Android, abstracting them into one common framework built on .NET." />
            <Span Text="&#10;&#10;"/>
            <Span Text="Use a single C# codebase and project system for all device targets to build apps that look and feel like the native platforms." />
            <Span Text="&#10;&#10;"/>
            <Span Text="Build beautiful apps faster and easier by integrating the power of Visual Studio with .NET MAUI." />
        </FormattedString>
    </Label.FormattedText>
</Label>   
<Style TargetType="Label">
    <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"/>
</Style>
bad.mp4

Setting the same on a Span type style does work.

<Style TargetType="Span">
    <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"/>
</Style>
good.mp4

Project:

templatetweak.zip

Steps to Reproduce

Go into the styles.xaml file of the attached file and comment out this line

   <Style TargetType="Span">
       <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"/>
   </Style>
  • run the app
  • change the theme of the device from light to dark (or visa versa) and notice that the text inside the span doesn't update.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms (confirmed in attached)

XamarinLabelRepro.zip

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

Styling the Span instead of just the Label.

Relevant log output

No response

Activity

  1. added
    t/bug
    potential-regression
    on Oct 10, 2023
  2. added this to the .NET 8 GA milestone on Oct 10, 2023
  3. ghost added
    legacy-area-controls
    on Oct 11, 2023
  4. added
    migration-compatibility
    on Oct 11, 2023
  5. removed
    potential-regression
    on Oct 14, 2023
  6. added
    s/verified
    s/triaged
    on Oct 16, 2023
  7. XamlTest commented on Oct 16, 2023

    @XamlTest

    Verified this on Visual Studio Enterprise 17.8.0 Preview 3.0(8.0.0-rc.2.9373). Repro on Android 13.0-API33 and iOS 16.4, not repro on Windows 11 with below Project:
    templatetweak (2).zip

  8. self-assigned this
    on Oct 17, 2023
  9. mattleibow commented on Oct 17, 2023

    @mattleibow
    Member

    Looking at the code, this code specifically does this:

    image

    Need to test on other platforms to see how they handle this.

  10. mattleibow commented on Oct 17, 2023

    @mattleibow
  11. moved this from Todo to In Progress in MAUI SDK Ongoingon Oct 18, 2023
  12. moved this from In Progress to Done in MAUI SDK Ongoingon Oct 23, 2023
  13. ghost locked as resolved and limited conversation to collaborators on Nov 22, 2023
  14. removed
    legacy-area-controls
    on May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-controls-labelfixed-in-8.0.0-rc.2.9511migration-compatibilityplatform/androidplatform/ioss/triageds/verifiedt/bug

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions