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

1

Good afternoon,

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

I did this:

    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

Doing this, I get the following error:

  

"Can not implicitly convert type void to   System.Windows.Documents.Block "

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

    
asked by anonymous 30.05.2017 / 20:36

1 answer

0

I managed to resolve. 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));
    
30.05.2017 / 22:02