C# – RichTextBox (WPF) does not have string property “Text”

crichtextboxwpfwpf-controls

I am trying to set/get the text of my RichTextBox, but Text is not among list of its properties when I want to get test.Text…

I am using code behind in C# (.net framework 3.5 SP1)

RichTextBox test = new RichTextBox();

cannot have test.Text(?)

Do you know how come it can be possible ?

Best Answer

to set RichTextBox text:

richTextBox1.Document.Blocks.Clear();
richTextBox1.Document.Blocks.Add(new Paragraph(new Run("Text")));

to get RichTextBox text:

string richText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;