Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roughiain opened this issue Aug 17, 2023 · 1 comment
Open

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

roughiain opened this issue Aug 17, 2023 · 1 comment
Labels
area-controls-label Label, Span area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Milestone

Comments

@roughiain
Copy link

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

@roughiain roughiain added the t/bug Something isn't working label Aug 17, 2023
@jsuarezruiz jsuarezruiz added the area-controls-label Label, Span label Aug 17, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Aug 17, 2023
@rmarinho rmarinho added the area-xaml XAML, CSS, Triggers, Behaviors label Aug 17, 2023
@rmarinho rmarinho added this to the Backlog milestone Aug 17, 2023
@ghost
Copy link

ghost commented Aug 17, 2023

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.

@hartez hartez changed the title Label().LoadFromXaml does not work when using Label.FormatedText Label().LoadFromXaml does not work when using Label.FormattedText Aug 17, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-label Label, Span area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants