Changing/Adding to the Style Gallery

2 posts, 0 answers
  1. Shahrzade
    Shahrzade avatar
    8 posts
    Member since:
    Feb 2016

    Posted 10 Mar Link to this post



    I would like to do some changes to the RichTextEditorRibbonBar's style gallery like changing the "Normal" style and adding/deleting new/existing styles.

    How can I do it programmatically?


  2. Hristo Merdjanov
    Hristo Merdjanov avatar
    662 posts

    Posted 11 Mar Link to this post

    Hello Shahrzade,

    Thank you for writing.

    In order to accomplish your task, you would need to work with the StyleRepository object exposed by the RadDocument class. Detailed information is available in the following documentation article: RadRichTextEditor | Styles.

    Please also check my code snippet below demonstrating how you can create a new style and modify an existing one: 
    // Add a new style
    StyleDefinition charStyle = new StyleDefinition();
    charStyle.Type = StyleType.Character;
    charStyle.SpanProperties.FontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily("Calibri");
    charStyle.SpanProperties.FontSize = Unit.PointToDip(20);
    charStyle.SpanProperties.ForeColor = Colors.Orange;
    charStyle.DisplayName = "charStyle";
    charStyle.Name = "charStyle";
    // Modify the normal style
    StyleDefinition normalStyle = this.radRichTextEditor1.Document.StyleRepository[RadDocumentDefaultStyles.NormalStyleName];
    normalStyle.ParagraphProperties.LineSpacing = 1;
    normalStyle.SpanProperties.ForeColor = Colors.Red;

    The styles defined in this manner will also be added to the Styles group in the ribbon bar.

    I hope this information was useful. Should you have further questions please do not hesitate to write back.

    Hristo Merdjanov
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top