dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.06k stars 1.73k forks source link

Label().LoadFromXaml does not work when using Label.FormattedText #16809

Open roughiain opened 1 year ago

roughiain commented 1 year ago

Description

When using

  var label = new Label().LoadFromXaml(xaml);

if the string contains formatted text it is ignored

    /// <summary>
    /// Taken from https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/label#use-formatted-text with the guesture recognizer removed.
    /// </summary>
    private static string xaml = """
          <Label LineBreakMode="WordWrap">
            <Label.FormattedText>
                <FormattedString>
                    <Span Text="Red Bold, " TextColor="Red" FontAttributes="Bold" />
                    <Span Text="default, " FontSize="14"/>                
                    <Span Text="italic small." FontAttributes="Italic" FontSize="12" />
                </FormattedString>
            </Label.FormattedText>
        </Label>
        """;

Full code

    /// <summary>
    /// Taken from https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/label#use-formatted-text with the guesture recognizer removed.
    /// </summary>
    private static string xaml = """
          <Label LineBreakMode="WordWrap">
            <Label.FormattedText>
                <FormattedString>
                    <Span Text="Red Bold, " TextColor="Red" FontAttributes="Bold" />
                    <Span Text="default, " FontSize="14"/>                
                    <Span Text="italic small." FontAttributes="Italic" FontSize="12" />
                </FormattedString>
            </Label.FormattedText>
        </Label>
        """;

    public MainPage()
    {
        InitializeComponent();
        var label = new Label().LoadFromXaml(xaml);
        if (label.FormattedText is null)
        {
            throw new Exception("This does not work");
        }
        TheVerticalStackLayout.Children.Add(label);
    }

Repo: https://github.com/roughiain/CanILoadFormttedTextInLoadFromXaml

Steps to Reproduce

clone and run

Link to public reproduction project repository

https://github.com/roughiain/CanILoadFormttedTextInLoadFromXaml

Version with bug

7.0.92

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

All platforms including Xamarin

Did you find any workaround?

No

Relevant log output

No response

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.