C# String in RichTextBox Wpf
I have the following question:
I have a class Question which has a property BodyString of the ty开发者_运维问答pe String. How do I put this String in a Wpf-RichTextBox?
yourRichTextBox.AppendText(BodyString);
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.
精彩评论