3

I have the following question:

I have a class Question which has a property BodyString of the type String. How do I put this String in a Wpf-RichTextBox?

Stef
  • 149
  • 3
  • 13

2 Answers2

6
yourRichTextBox.AppendText(BodyString);
oopbase
  • 11,157
  • 12
  • 40
  • 59
1

From this answer:

The WPF RichTextBox has a Document property for setting the content a la MSDN:

// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();

// Add paragraphs to the FlowDocument.
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 1")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 2")));
myFlowDoc.Blocks.Add(new Paragraph(new Run("Paragraph 3")));
RichTextBox myRichTextBox = new RichTextBox();

// Add initial content to the RichTextBox.
myRichTextBox.Document = myFlowDoc;

You can just use the AppendText method though if that's all you're after.

Hope that helps.

Raz Luvaton
  • 3,166
  • 4
  • 21
  • 36
Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118