简体   繁体   English

如何将label的部分加粗?

[英]How to bold part of label?

How to bold part of label?如何将label的部分加粗?

I need something like:我需要这样的东西:

I am a label with some bold text我是 label,有一些粗体

My XAML:我的XAML:

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

If you use a TextBlock instead of a Label you can bold a part of the text by using <Bold> : 如果使用TextBlock而不是Label ,则可以使用<Bold>来加粗文本的一部分:

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

But if you have to use a Label you can nest a TextBlock inside a Lable : 但是,如果必须使用Label ,则可以在Lable嵌套一个TextBlock

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

in case anyone wants to do this in code behind:如果有人想在后面的代码中这样做:

var tbl = new TextBlock();
tbl.Inlines.Add(new Run("normalText") { });
tbl.Inlines.Add(new Run("boldText") { FontWeight = FontWeights.Bold });
yourLabel.Content = tbl;

output will be: output 将是:

normalText boldText普通文本粗体文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM