【问题标题】:WPF textblock, mixing of foreground colorWPF文本块,前景色混合
【发布时间】:2013-11-06 01:48:39
【问题描述】:

在 WPF 文本块中,如何使文本中的内容具有不同的颜色。

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

例如,整个句子都是白色的,但是我需要“Player 1”和“CK”是不同的颜色,WPF可以做到吗?

【问题讨论】:

    标签: wpf textblock foreground


    【解决方案1】:

    您可以使用 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>
    

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 1970-01-01
      • 2011-09-28
      • 2021-04-10
      • 1970-01-01
      • 2014-11-22
      • 2013-01-29
      • 2014-05-19
      相关资源
      最近更新 更多