문제

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