How do I set formatted text in Silverlight RichTextBox?
How can I make a RichTextBox show a string with format?
I'm using Run but it dosen't work:
 // create a paragraph
 Paragraph prgParagraph = new Paragraph();
 prgParagraph.FontFamily = new FontFamily("Comic Sans MS");
 // create 开发者_运维百科some text, and add it to the paragraph
 Run rnMyText = new Run();
 rnMyText.Text = w.meaning;
 prgParagraph.Inlines.Add(rnMyText);
 rtxtMeaning.Blocks.Add(prgParagraph);
I know that this question is a couple years old, but I had the same question and here's what I came up with. I've tested it a few times with my Silverlight 5 project and it works for me.
public static void setRtf(ref RichTextBox rtfBox, string text)
{
     Paragraph p = new Paragraph();
     p.FontFamily = rtfBox.FontFamily;
     Run pTxt = new Run();
     pTxt.Text = text;
     p.Inlines.Add(pTxt);
     rtfBox.Blocks.Clear();
     rtfBox.Blocks.Add(p);
}
make sure that when you call the method you use the ref keyword for your RichTextBox object and you're good to go =)
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论