简体   繁体   中英

How to display content from a RichTextBox in another RichTextBox

I have two RichTextBoxes: One that the user will enter and edit text on. The other will obtain the text from the first RichTextBox and display it to the user (this is similar to how you would obtain text from a TextBox and display it on a TextBlock, but I don't think you can display styled text on a regular TextBlock). But how do I get the text from the first RichTextBox with all the styles included (that is, text that has been bolded, underlined, had its font size changed, etc) and display it on the second RichTextBox. It seems when I first tried:

TextRange text = new TextRange(firstRichTextBox.Document.ContentStart, firstRichTextBox.Document.ContentEnd);
secondRichTextBox.AppendText(text.Text);

It only displays plain text, and not the styled text. How do I obtain the styled text from the first RichTextBox and display it on the second RichTextBox

In order to get stylized text from one richTextBox to Another you must use something as follows:

secondRichTextBox.Rtf = firstRichTextBox.Rtf;

Of course, you should add some logic, not just copy from one to another

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM