本文介绍了如何在Silverlight RichTextBox中设置格式化文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使一个 RichTextBox 显示一个带格式的字符串?

我正在使用运行但它不工作:

  //创建段落
段落prgParagraph = new Paragraph();
prgParagraph.FontFamily = new FontFamily(Comic Sans MS);

//创建一些文本,并将其添加到段落
运行rnMyText = new Run();
rnMyText.Text = w.meaning;

prgParagraph.Inlines.Add(rnMyText);

rtxtMeaning.Blocks.Add(prgParagraph);


解决方案

我知道这个问题已经有几年了,但我有同样的问题,这就是我想出的。我测试了几次我的Silverlight 5项目,它适用于我。

  public static void setRtf(ref RichTextBox rtfBox,字符串文本)
{
段落p =新的段落();
p.FontFamily = rtfBox.FontFamily;
运行pTxt = new Run();
pTxt.Text = text;
p.Inlines.Add(pTxt);
rtfBox.Blocks.Clear();
rtfBox.Blocks.Add(p);
}

请确保在您调用RichTextBox的ref关键字的方法对象,你很好=)


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

这篇关于如何在Silverlight RichTextBox中设置格式化文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:45