How to add multiple Runs in a paragraph with a part of the Bold string in WPF

Asked

Viewed 32 times

1

Good afternoon,

I’m completely new to WPF, so forgive me if the question is stupid. I need to format two strings that are contained in the same paragraph, one in bold, and the other in normal text.

I did it this way:

    Bold sting1 = new Bold(new Run(string.Format("{0}:", item.Chave))); // primeira parte

    Run string2= new Run(string.Format("\t{0}", item.Valor)); // segunda parte

    p1 = new Paragraph(string1).Inlines.Add(string2);// p1 já foi declarado como Block em outra parte do código

In doing so, I get the following error:

"Cannot implicitly Convert type void to System.Windows.Documents.Block"

I’d appreciate it if someone had a light. Thank you very much for your attention.

  • You’re adding these strings where?

  • Add at the end: flowDoc.Document.Blocks.Add(P1); But I already got it here. I really appreciate your help. =)

1 answer

0


I got it. Instead of:

Bold sting1 = new Bold(new Run(string.Format("{0}:", item.Chave))); 
Run string2= new Run(string.Format("\t{0}", item.Valor));
p1 = new Paragraph(string1).Inlines.Add(string2);

I used the following code:

p1 = new Paragraph();
(p1 as Paragraph).Inlines.Add(new Bold(new Run(item.Chave + ":\t")));
(p1 as Paragraph).Inlines.Add(new Run(item.Valor));

Browser other questions tagged

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