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

Remove standard Styles

6 Answers 229 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Sebastian
Top achievements
Rank 1
Sebastian asked on 18 Feb 2015, 09:06 AM
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.

6 Answers, 1 is accepted

Sort by
0
Accepted
Mihail
Telerik team
answered on 20 Feb 2015, 02:04 PM
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.

 
0
Sebastian
Top achievements
Rank 1
answered on 20 Feb 2015, 02:11 PM
Thank you, it works :)
0
John
Top achievements
Rank 1
answered on 19 Mar 2020, 12:15 PM

Hi

I'm trying to apply this pattern (setting IsPrimary to false) on table and list styles.  Broadly I'm trying to create a style sheet that includes all of the builtin styles so that I can remove them from the RichTextBoxUI style galleries and later only bring a limited set back in.

Aside from looping through the Heading styles as above, I see that there's a static class that allows you to get hold of the styles (the 'Dump' being a LInqpad method):

//Returns Headings,Caption and Hyperlink
BuiltInStyles.GetAllPrimaryStyles().Dump(1);

 

//Returns (205) table styles, all IsPrimary = false

BuiltInStyles.GetAllStyles(StyleType.Table).Dump(1);

 

However, if you look at the results of the second line, you see that all of those table styles have their IsPrimary property already set to false.

 

Is there a good way to hide these table and list styles in the UI so that I can set the ones that do get shown?

 

Thanks

 

John

 

0
Dimitar
Telerik team
answered on 23 Mar 2020, 02:07 PM

Hello John,

I have examined this and there is no way to remove the styles. The styles in the gallery are directly bound to the built-in styles and our implementation does not allow their removing. What I can suggest is creating a separate custom control and adding the desired styles to it. 

Let us know if you have any other questions.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
John
Top achievements
Rank 1
answered on 23 Mar 2020, 02:17 PM

Hello Dimitar,

Thanks very much for looking.  I'll go ahead and implement as you suggest.

For future releases, it would be great if a) table styles used IsPrimary to populate the gallery as per Headings, and b) if RichTextBoxRibbonUI has a property to default all built-in styles to have IsPrimary set to false so that you could more easily start off with a limited set of available styles.

Anyway, thanks again for your help.

Best regards

John

0
Dimitar
Telerik team
answered on 24 Mar 2020, 08:45 AM

Hello John,

Thank you for your feedback. We will consider adding a feature request for this functionality if we receive more requests for it.

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
RichTextBox
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Sebastian
Top achievements
Rank 1
John
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or