How to add a Label inside a Textblock by code Behind

Asked

Viewed 187 times

2

How do I add these Labels within the TextBlock, for code behind?

<TextBlock>
    <Label x:Name="NumeroPergunta" FontWeight="Bold" />
    <Label x:Name="Pergunta" />
</TextBlock>

What I have so far:

var tbPergunta = new TextBlock {Text = pergunta.Pergunta};

1 answer

1


I got it using the property Inlines of Textblock:

First I created the Labels dynamically:

var lblNumeroPergunta = new Label
{
    Content = contNumeroPerguntas.ToString(),
    FontWeight = FontWeights.Bold
};
var lblPergunta = new Label { Content = pergunta.Pergunta };

Then I created the TextBlock

var tbPergunta = new TextBlock();

And finally, using the property Textblock.Inlines., managed to add the Labels:

tbPergunta.Inlines.Add(lblNumeroPergunta);
tbPergunta.Inlines.Add(lblPergunta);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.