質問

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?

役に立ちましたか?

解決

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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top