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();
foreach
(var style
in
editor.Document.StyleRepository)
editor.Document.StyleRepository.Remove(style);
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
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.
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
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
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
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
Our thoughts here at Progress are with those affected by the outbreak.