Question

In WPF textblock, how do I make the content inside the text having different colors.

<Label FontSize="32" Foreground="White">
        <TextBlock TextWrapping="Wrap" Text="Player 1 just win XXX Game from CK." />
</Label>

For example, the whole sentences is in white color, but I need "Player 1" and "CK" to be in different color, can WPF do that?

Was it helpful?

Solution

You can do that using Inlines

<TextBlock TextWrapping="Wrap">
     <TextBlock.Inlines>
         <Run Foreground="Red" Text="Player 1"/>
         <Run Foreground="White" Text=" just win XXX Game from"/>
         <Run Foreground="Green" Text=" CK" />
     </TextBlock.Inlines>
</TextBlock>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top