I’m using the RichTextBox to display some readonly text that I have to markup on the fly.
How can I pass markup codes in text to have it rendered by the RichTextBox control?
For example, I’d like to pass this is \cf6 sample \cf1 text to the richtextbox for it to render.
Right now, I build a FlowDocument and add the text value to a run object, but the text gets rendered literally.
RichTextBox fieldLabel = new RichTextBox();
FlowDocument flowDoc = new FlowDocument();
Paragraph myPara = new Paragraph();
Run myRun = new Run(content);
myPara.Inlines.Add(myRun);
flowDoc.Blocks.Add(myPara);
fieldLabel.Document = flowDoc;
I want to see the value in red, but I see the markup instead.
Thanks in advance for any input.
You cant assign RTF text just like that. You need to get that text into a stream and then pass that stream to the RichTextBox.Selection.Load() method. e.g.