Silverlight 4 RichtTextBox - how do I get the text without the formatting?

2.4k Views Asked by At

How do I get the text out of a Silverlight 4 RichTextBox without the formatting? I know the Xaml property will give me the XAML but I just want the text.

3

There are 3 best solutions below

2
On

If you just want text, why not use TextBox instead?

0
On

This is a little late, but I will post anyway. There is a trick that involves selecting all the text in code and then accessing the Text propety of the TextSelection object. Like so:

myRichTextBox.SelectAll();
var plainText = myRichTextBox.Selection.Text;

I am using it in my apps and although it is not the prettiest solution, it works. Found it here:
http://forums.silverlight.net/forums/p/184560/422007.aspx

1
On

There are various third-party components that support this kind of functionality (unfortunately paid). For example, Telerik's RadRichTextBox supports both highlighting and exporting rich text content as plain text, latter trough component called TxtFormatProvider.