Remove standard Styles

3 posts, 1 answers
  1. Sebastian
    Sebastian avatar
    9 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2015 Link to this post

    Hello,

    i want to remove all Styles from the StyleRepository of the current RadDocument and add my own StyleDefinitions.

    The adding of StyleDefinitions works fine, but I can't remove the standard Style.
    I tried it with
    editor.Document.StyleRepository.Clear();
    or
    foreach (var style in editor.Document.StyleRepository)
    editor.Document.StyleRepository.Remove(style);
    or
    foreach (var style in editor.Document.StyleRepository)
    style.IsPrimary = false;

    But allways threre are more Styles than my own in the StyleGallery.
  2. Answer
    Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 20 Feb 2015 Link to this post

    Hello Sebastian,

    From what I understand your goal is to remove all styles from the styles gallery except your custom styles. 

    Initially RadDocument contains only default styles which are important for normally functioning document and they should not be removed. All other styles which you see in the styles gallery are built in styles which will be added to the document on the first using. This is done for performance optimizations. To remove them from the gallery you will need to first register them to the document and then set the IsPrimary property to false.
    Here is example on how this could be done:
    for (int headingIndex = 1; headingIndex <= 9; headingIndex++)
    {
        this.radRichTextBox.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(headingIndex)).IsPrimary = false;
    }
                 
    this.radRichTextBox.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.CaptionStyleName).IsPrimary = false;
    this.radRichTextBox.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.HyperlinkStyleName).IsPrimary = false;
    this.radRichTextBox.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.NormalStyleName).IsPrimary = false;

    I hope this information is helpful for you.

    Regards,
    Mihail
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sebastian
    Sebastian avatar
    9 posts
    Member since:
    Feb 2015

    Posted 20 Feb 2015 Link to this post

    Thank you, it works :)
Back to Top