【问题标题】:Set/change text weight within the Text property of a TextBlock在 TextBlock 的 Text 属性中设置/更改文本粗细
【发布时间】:2013-08-08 21:11:00
【问题描述】:

我希望能够在TextBlockText 属性字符串中更改文本的粗细(例如,从普通更改为粗体然后再返回)(可能使用一些控制字符集)。这甚至可能吗?

【问题讨论】:

  • @H.B.像 <TextBlock Text="This is <b>special</b> text" /> (如果它做了类似 HTML 的事情)

标签: wpf xaml textblock


【解决方案1】:

TextBLock.Text 创建单个 Run,您可以设置自定义 Inlines

<TextBlock>
    Text with <Bold>bold</Bold> within.
<TextBlock>

显然它不再使用Text 属性。

【讨论】:

  • 我更喜欢内联的这个答案,乍一看我一定不明白。 +1
【解决方案2】:

你是在说这样的事情吗?

<TextBlock>
    <Run Text="Hey it's Normal Text"/>
    <Run Text="Hey it's Bold Text" FontWeight="Bold"/>
    <Run Text="Hey it's Colored Text" Foreground="Green"/>
</TextBlock>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 2018-01-30
    相关资源
    最近更新 更多