We built an application in XAML. Now I need to format the text strings. Is it possible to bold only part of the text string. We are replacing an element's text in a XAML textblock with a text string. What would be the easiest way to make parts of the text string bold? Would I add a label? Something else in the XAML or in the C#?
Here is an example of our XAML and our code behind:
XAML
<TextBlock x:Name="PrimaryNameText" Text="Primary Member Name:"></TextBlock>
C# String
PrimaryNameText.Text = "Primary Member Name: " + reAccount.MyPerson.Prefix + " " + reAccount.MyPerson.FirstName + " " + reAccount.MyPerson.LastName;
In the example above, we more or less want to bold the part of the string "Primary Member Name: "
I know you can do a "\n" for a page break, is there a way we can do something for bolding text in the string?
Use a span inside your TextBlock.
<TextBlock>
<Span x:Name="PrimaryNameBold" FontWeight="Bold"></Span>
<Span x:Name="PrimaryNameNormal"></Span>
</TextBlock>
And in your code:
PrimaryNameBold.Text = "Primary Member Name: ";
PrimaryNameNormal.Text = reAccount.MyPerson.Prefix + " " + reAccount.MyPerson.FirstName + " " + reAccount.MyPerson.LastName;
Not an awesome solution, but this should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With