user9653128
user9653128

Reputation:

How to bold part of label?

How to bold part of label?

I need something like:

I am a label with some bold text

My XAML:

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

Upvotes: 4

Views: 3966

Answers (3)

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:

normalTextboldText

Upvotes: 0

Shloime Rosenblum
Shloime Rosenblum

Reputation: 1020

<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>

Upvotes: 2

Slaven Tojić
Slaven Tojić

Reputation: 3014

If you use a TextBlock instead of a Label you can bold a part of the text by using <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 x:Name="Mylabel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10">
     <TextBlock>I am a label with some <Bold>bold</Bold> text</TextBlock>
</Label>

Upvotes: 2

Related Questions