This is a migrated thread and some comments may be shown as answers.

RadRichTextBox silverlight changing text color

10 Answers 273 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Nuno Oliveira
Top achievements
Rank 1
Nuno Oliveira asked on 25 Mar 2011, 07:12 PM
Hi,


I am having difficulties finding a way of changing the text color of the entire document.
I have a simple plain text document for wich I need the font color (foreground color, text color, whatever) to be white.

I have seen several examples but none works for me.

Is there a way of just change the text color for the document? Or, is there a way of changing the default text color of the richtextbox that stays unchanged even after loading a new plain text document?

Regards,

Nuno

10 Answers, 1 is accepted

Sort by
0
Ivailo Karamanolev
Telerik team
answered on 29 Mar 2011, 09:36 AM
Hello Nuno Oliveira,

There is no way to set the default fore color of the document. Some spans may have fore colors set explicitly, so such an approach would not work. Instead, you should enumerate all spans and set their respective fore color. That's most easily done like this:
foreach(Span span in document.EnumerateChildrenOfType<Span>()) {
    span.ForeColor = Colors.White;
}

Kind regards,
Ivailo
the Telerik team
0
Toby Riley
Top achievements
Rank 1
answered on 07 Apr 2011, 03:48 PM
How would I do this for an entire document?

I want the default forecolor colour to be white against a background of black.

If I was to use your code below what event would I hook that up to?

Thanks T.
0
Alex
Telerik team
answered on 13 Apr 2011, 03:56 PM
Hi Tobias Riley,

In your scenario you can use the DefaultStyleSettings property of RadDocument. Here is how to set the default fore color of the text to white:

document.DefaultStyleSettings.SetPropertyValue(Span.ForeColorProperty, Colors.White);
Note that this will affect all spans in the document that have no explicitly set ForeColor. In many cases when importing the RadDocument using FormatProvider class, all the imported spans will have their properties explicitly set so you may still have to process the document (as sown in the previous post) after it has been imported.

As for the background - the easiest solution is to set the Background property of the RadRichTextBox control that will show the document.

Kind regards,
Alex
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Roussel
Top achievements
Rank 2
answered on 11 Oct 2013, 12:21 PM
For now I don't understand where do I put this code.  What is document ? It doesn't find it nor the Span.ForeColorProperty
Silverlight 5
Telerik 2013.2.923.1050

Thank you
0
Marc Roussel
Top achievements
Rank 2
answered on 11 Oct 2013, 12:22 PM
DefaultStyleSetting isn't found either in the MyRichTextBox.Document object
0
Marc Roussel
Top achievements
Rank 2
answered on 11 Oct 2013, 12:23 PM
Even thought I have the Background to black and the Foreground to white in the property of the RichTextBox, I style don't see anything when I write into it !
0
Marc Roussel
Top achievements
Rank 2
answered on 11 Oct 2013, 12:24 PM
I tried this : CustomerConnectionInfo.ChangeTextForeColor(Colors.White);
No luck !
0
Marc Roussel
Top achievements
Rank 2
answered on 11 Oct 2013, 12:31 PM
I tried this.
foreach(Span span in document.EnumerateChildrenOfType<Span>()) {
    span.ForeColor = Colors.White;


  It seems to work however there's a few things not working fine.
When I do it, nothing happens unless I scroll into the RichTextBox or I type in it then I see the white text appearing

Also the Caret isn't visible. 
0
Petya
Telerik team
answered on 16 Oct 2013, 08:21 AM
Hi,

As this thread is rather old, the ways to change the style settings in RadRichTextBox have changes.

In case you wish to set particular style settings to the editor so that all documents shown in it will use those settings, you can refer to this help article.

I suggest you also get familiar with the styling concept of the control as it provides a way to easily apply different sets of styles to parts of the document. You can check this article to learn about the types of styles, their creation and evaluation and here you can read how to use the UI of the feature.

I hope this helps!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Marc Roussel
Top achievements
Rank 2
answered on 16 Oct 2013, 09:20 AM
Ok Thank you for the information...
Tags
RichTextBox
Asked by
Nuno Oliveira
Top achievements
Rank 1
Answers by
Ivailo Karamanolev
Telerik team
Toby Riley
Top achievements
Rank 1
Alex
Telerik team
Marc Roussel
Top achievements
Rank 2
Petya
Telerik team
Share this question
or