Hello,
Maui provides two ways to bold text on a page using a Label control. One is through HTML, and the other is through FormattedString.
You could refer to the following code snippet and official documentation to understand this workaround.
Workaround 1: Html Type:
Step 1. Define a Label control on the page, or you can create a Label class in the code-behind.
<Label x:Name="bold_sample_label"/>
Step 2. Use Html formatting text to bold specific content in a string.
int value1 = 0;
decimal value2 = 9.02m;
bold_sample_label.Text = string.Format($"You have <span ><strong>{0}</strong></span> unpaid invoices totaling <span ><strong>${1:F2}</strong></span>.", value1, value2);
bold_sample_label.TextType = TextType.Html;
Workaround 2: FormattedString:
Step 1. The same as Step 1 of Workaround 1.
Step 2. Divide the string into sections, add content and styles, and assign values to Label.
FormattedString formattedString = new FormattedString();
formattedString.Spans.Add(new Span { Text = "You have ", });
formattedString.Spans.Add(new Span { Text = value1.ToString(), FontAttributes = FontAttributes.Bold});
formattedString.Spans.Add(new Span { Text = " unpaid invoices totaling " });
formattedString.Spans.Add(new Span { Text = string.Format($"${1:F2}.",value2), FontAttributes = FontAttributes.Bold });
bold_sample_label.FormattedText = formattedString;
Documentation:
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.