RadRichTextBox silverlight changing text color

11 posts, 0 answers
  1. Nuno Oliveira
    Nuno Oliveira avatar
    10 posts
    Member since:
    Jan 2006

    Posted 25 Mar 2011 Link to this post

    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
  2. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 29 Mar 2011 Link to this post

    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
  3. DevCraft banner
  4. Toby Riley
    Toby Riley avatar
    40 posts
    Member since:
    Aug 2012

    Posted 07 Apr 2011 Link to this post

    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.
  5. Alex
    Admin
    Alex avatar
    129 posts

    Posted 13 Apr 2011 Link to this post

    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
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 11 Oct 2013 Link to this post

    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
  7. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 11 Oct 2013 Link to this post

    DefaultStyleSetting isn't found either in the MyRichTextBox.Document object
  8. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 11 Oct 2013 Link to this post

    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 !
  9. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 11 Oct 2013 Link to this post

    I tried this : CustomerConnectionInfo.ChangeTextForeColor(Colors.White);
    No luck !
  10. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 11 Oct 2013 Link to this post

    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. 
  11. Petya
    Admin
    Petya avatar
    975 posts

    Posted 16 Oct 2013 Link to this post

    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 >>
  12. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 16 Oct 2013 Link to this post

    Ok Thank you for the information...
Back to Top
DevCraft banner