如何将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
Contentstring 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 likeFontWeight="Bold", while keeping the rest of the text in the default style.
内容的提问来源于stack exchange,提问作者user9653128




