0

I have a TextBlock object with a bound Text property.

I cannot control the binding source, but I can change Binding and TextBlock.

I want to format some key word display style...


For example:

I want to formart word "key" to bold, and formart word "RED" to red color,

And source data is "Example keyword and RED word".

After formatting, the equivalent Xaml should be

Example <Bold>key</Bold>word and <Span Foreground="Red">RED</Span> word

Of course, if the source was changed, Text must also changing synchronously.

What should I do?

1 Answers1

1

You can use TextBlock.inlines like below-

<TextBlock.Inlines>
    <Run FontWeight="Bold" FontSize="14" Text="Key" />
    <Run Foreground="Red" Text="Red" />
</TextBlock.Inlines>

You can also use binding for Text property in inlines.

You can refer this example.

Gaurav Jalan
  • 467
  • 2
  • 14