I've had the need to programmatically customize and lock the provided Styles Gallery to set of my choosing.
I need to do this in order to lock the users into a predefined set of styles. I intend the result to be exported as html, and it would be nice on the design surface that what the user sees matches (as close as I can) preexisting css rules. I like the existing WYSIWYG feature, but for the current project at hand that is irrelevant right now.
Are there any plans to expose the APIs for the styles gallery? Am I missing something obvious if this is already doable?
Thanks,
Lester
8 Answers, 1 is accepted
The styles shown in the Styles Gallery of the predefined UI are the same as those in the document's StyleRepository. You can read all about styles and how to create a custom one in this help article and about the UI here.
Additionally, you can remove one of the default styles like this:
this
.editor.Document.StyleRepository.Remove(
"Heading1"
);However, plea
this
.editor.Document.StyleRepository.GetValueOrNull(
"Hyperlink"
).IsPrimary =
false
;
This should be enough to verify that users will not be able to use them if you also remove the Change Styles button from the ribbon, which invokes the ManageStylesDialog.
Please note that StyleRepository is a property of RadDocument, so once you change the document in the editor or create a new one, previously removed styles might again be present in the gallery. In order to achieve the desired result for all documents you should execute the code mentioned above in the DocumentChanged event handler of RadRichTextBox.
I hope the provided information is helpful! Let me know if I can be of further assistance.
Regards,
Petya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I am trying to do similar thing - customize styles available via Styles Gallery.
I've tried to do as you directed topic starter, but when I receive DocumentChanged event - StylesRepository does not contain Header1..6 and some other styles in it. If I add my own Header1..3 styles, later someone is overwriting them in that collection. The only 2 things that work:
- change "normal" style (since it exists in StylesRepository at the moment of event)
- set "Hyperlink" style IsPrimary property to false (same - works because style exists at the moment of event)
Can you tell me - if anything changed in that logic (when and how can I add/remove/change styles in styles gallery) since your original post here?
Regards, Dmitry.
We recently added the concept of built-in styles - they are added to the repository only as metadata and are created on demand. Hyperink and Heading1-6 are such styles.
By default, GetValueOrNull adds the style in the repository, so if you first invoke this method, you can then remove the style with the Remove method.
Regards,
Boby
Telerik
What I meant was that you can first get the style - this will ensure that it is added to the repository - and then remove it, for example:
string
heading2StyleId = RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(2);
var heading2Style =
this
.radRichTextBox.Document.StyleRepository.GetValueOrNull(heading2StyleId);
this
.radRichTextBox.Document.StyleRepository.Remove(heading2StyleId);
Regards,
Boby
Telerik
creates and adds a new style to the MS Word styles list.
StyleDefinition paragraphStyle = new StyleDefinition();
paragraphStyle.Type = StyleType.Paragraph;
paragraphStyle.BasedOn = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1)];
paragraphStyle.ParagraphProperties.Background = Colors.Red;paragraphStyle.DisplayName = "myStyle";
paragraphStyle.Name = "myStyle"; this.radRichTextBox.Document.StyleRepository.Add(paragraphStyle);
http://www.telerik.com/forums/how-to-programatically-insert-a-table-of-contents
1.
string
heading2StyleId = RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(2);
2.
var heading2Style =
this
.radRichTextBox.Document.StyleRepository.GetValueOrNull(heading2StyleId);
3.
this
.radRichTextBox.Document.StyleRepository.Remove(heading2StyleId);
I've tried the above code provided and it didn't remove Heading 2 from my quick styles. Is this a known issue and is there another method for removing styles?
Thanks,
Robert
In order to hide a style from the quick styles gallery, you could set its IsPrimary property to false. This indicates the property will be no longer visible in the gallery. However, the provided code-snippet should also works, so please, ensure you that you are not adding the removed style after the code execution. If this is not the case, you can try to isolate the issue and send it to us as a demo project.
Please note that in the current implementation of the RadRichTextBox there isn't a way to remove the style from ManageStylesDialog. That dialog is shown when you click on the 'Change Styles' button next to the gallery in the RibbonUI.
Regards,
Todor
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 Jhon,
You could use the RadComboBox control to implement such a UI. RadRichTextBox doesn't provide such kind of styles gallery and you will need to implement custom logic for populating and applying the styles.
Hi Tanya and telerik team
Thank you for your information.
I know that. I build a Editor base on telerik's editor.
When I custom logic for populating and applying the style as same as Styles gallery in selection changed of combobox.
But I get some issues about CTRL+Z.
Ex: my heading 1 have styles are fontSize = 48 I use radRichTextBox.ChangeFontSize(48),
fontWeight=Normal I use radRichTextBox.ChangeFontWeight(FontWeights.Normal)
spacingBefore=0, spacingAfter=0 some things like that.
Then I CTRL+Z radRickTextBox undo step by step. About viewer it's not good.
So can you provide a solution to me or set track revision = false.
Thank you again!
Hi Jhon,
There are two approaches you can use. The first one is to generate a style with the properties you need and directly apply it when selected by the user. The second option is to use the BeginUndoGroup and EndUndoGroup methods of the History to group the modifications as a single entry in the History stack.
Hope this is helpful.
Have a nice day, Tanya!
That so good. I resolved my issues base on your suggestion.
Thank you so much. And hope you have all the best things.
I have an issue about spellcheck when I change my computer language.
I try apply xml:lang="vi-VN" or another language but spellcheck doesn't work.
<telerik:RadRichTextBox x:Name="radRichTextBox" xml:lang="vi-VN" IsSpellCheckingEnabled="True" IsContextMenuEnabled="True" LayoutMode="Paged"/>
Or set the culture:
((DocumentSpellChecker)radRichTextBox.SpellChecker).SpellCheckingCulture = culture ;
Spellcheck still doesn't work.
Could you suggest solution for it.
Please help again.
Hi Jhon,
You need to load a dictionary corresponding to the specific culture. Please, check the Spellcheck help topic for more details on how to do that.
On a side note, I would like to ask you to open new threads for the different questions you might have. This will allow us to keep the forum threads focused and in good order. Thank you for understanding.
Have a nice day, Tanya!
I deployed editor'telerik to computers in the office. But spellcheck doesn't work on some computer.
I set default enable is "True".
And add references Telerik.Windows.Documents.Proofing.Dictionaries.En-US.dll assembly
and Telerik.Windows.Documents.Proofing.dll assembly.
Set culture is "en-US".
Please help or could you open new thread about issues to us follow together.
Because I don't know how to open a new thread.
Hi Jhon,
I would suggest that the dictionary is not loaded for some reason on the specific machines. RadRichTextBox uses MEF to load some of its parts and the framework could fail to load necessary types. You can manually define the catalog for the control to avoid missing some of them. More information on how that can be done is available in the MEF help topic.
A new post in the forums can be submitted by clicking the Ask Question button on the top of the page. Here is an image to better show it: