You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何将Label控件的部分文本设置为加粗?

How to Make Part of Label Text Bold in XAML

Got it, let's sort this out! Your current Label uses a plain string for its Content property, which doesn't support partial text formatting. To get that bold segment in your label text, you'll need to use a TextBlock as the Label's content—since TextBlock allows mixing inline elements with different styles.

Here's the adjusted XAML code you need:

<Label x:Name="Mylabel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10">
    <TextBlock>
        I am a label with some <Run FontWeight="Bold">bold</Run> text
    </TextBlock>
</Label>

Quick explanation:

  • We swapped out the plain Content string for a TextBlock nested inside the Label. Label can host any UIElement as its content, not just plain text.
  • The <Run> element lets us target specific text segments (here, the word "bold") and apply formatting like FontWeight="Bold", while keeping the rest of the text in the default style.

内容的提问来源于stack exchange,提问作者user9653128

火山引擎 最新活动