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

Customizing Styles Gallery in the Ribbon

8 Answers 239 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Lester
Top achievements
Rank 1
Lester asked on 04 Apr 2013, 09:07 PM
Hello,

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

Sort by
0
Accepted
Petya
Telerik team
answered on 09 Apr 2013, 03:01 PM
Hello Lester,

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
However, you should be aware that there are some styles, namely Normal, TableNormal, TableGrid and Hyperlink, which are internally used and removing them might cause unexpected crashes. What you can do in this regard is simply set their IsPrimary property to false, which will hide them to from the Quick Styles:
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.

0
Dmitry
Top achievements
Rank 1
answered on 25 Jun 2014, 11:24 AM
Hello Petya!
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.
0
Boby
Telerik team
answered on 26 Jun 2014, 11:44 AM
Hello 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
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Dmitry
Top achievements
Rank 1
answered on 26 Jun 2014, 01:31 PM
Can you please provide an example how to do this?
0
Boby
Telerik team
answered on 30 Jun 2014, 02:22 PM
Hi Dmitry,
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
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
C
Top achievements
Rank 1
answered on 03 Jul 2014, 04:16 PM
This code from http://www.telerik.com/forums/how-to-programatically-insert-a-table-of-contents
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
0
Robert
Top achievements
Rank 1
answered on 12 Dec 2014, 10:59 AM
I'm experiencing the exact same situation as Dmitry, 

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
0
Todor
Telerik team
answered on 17 Dec 2014, 08:30 AM
Hello 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.

 
Jhon
Top achievements
Rank 1
Iron
commented on 13 Oct 2021, 04:11 AM | edited

Hello Telerik team,

How to build styles gallery as the same dropdown both UI and code behind?

Please see the image in attach file.

Tanya
Telerik team
commented on 15 Oct 2021, 12:49 PM

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.

Jhon
Top achievements
Rank 1
Iron
commented on 21 Oct 2021, 05:06 AM | edited

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!

Tanya
Telerik team
commented on 25 Oct 2021, 04:27 PM

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.

Jhon
Top achievements
Rank 1
Iron
commented on 26 Oct 2021, 06:54 AM

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.

Jhon
Top achievements
Rank 1
Iron
commented on 27 Oct 2021, 02:29 AM | edited

Hi Tanya and Telerik team,

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:
var culture = CultureInfo.GetCultureInfo("vi-VN");
((DocumentSpellChecker)radRichTextBox.SpellChecker).SpellCheckingCulture = culture ;
Spellcheck still doesn't work.
Could you suggest solution for it.

Please help again.

Tanya
Telerik team
commented on 28 Oct 2021, 12:51 PM

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.

Jhon
Top achievements
Rank 1
Iron
commented on 06 Nov 2021, 02:31 AM

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.

Thank you so much, Tanya!


Tanya
Telerik team
commented on 10 Nov 2021, 02:15 PM

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:

Tags
RichTextBox
Asked by
Lester
Top achievements
Rank 1
Answers by
Petya
Telerik team
Dmitry
Top achievements
Rank 1
Boby
Telerik team
C
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Todor
Telerik team
Share this question
or