SGarratt
SGarratt

Reputation: 1004

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

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.

Upvotes: 2

Views: 2391

Answers (3)

Henrik Söderlund
Henrik Söderlund

Reputation: 4328

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

Upvotes: 2

Borislav Ivanov
Borislav Ivanov

Reputation: 5360

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.

Upvotes: 0

Austin Lamb
Austin Lamb

Reputation: 3116

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

Upvotes: 0

Related Questions