Add New Keyword to Existing Tagger
Environment
| Product Version | Product | Author |
|---|---|---|
| 2023.1.314 | RadSyntaxEditor for WinForms | Dinko Krastev |
Description
The RadSyntaxEditor control provides a set of predefined taggers to style specific words in the document. In this article, we will demonstrate how we can add keywords to a predefined tagger without creating a custom tagger from scratch. In the following image, you can observe how the Telerik word is marked by the tagger.

Solution
You can create a custom class that inherits the desired tagger. Then you can override the GetWordsToClassificationTypes() method and modify the Dictionary return from the base class. This method will be called multiple times, so you will need to add a check if the given key already exists. For this tutorial, we are going to extend the CSharpTagger and we will add "Telerik" keyword which will be marked by the tagger.
public class MyTagger : CSharpTagger
{
public MyTagger(RadSyntaxEditorElement editor)
: base(editor)
{
}
protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
{
Dictionary<string, ClassificationType> baseTypes = base.GetWordsToClassificationTypes();
if(!baseTypes.ContainsKey("Telerik"))
{
baseTypes.Add("Telerik", ClassificationTypes.Keyword); // or any other ClassificationTypes
}
return baseTypes;
}
}
What's left is to register the extended predefined tagger.
MyTagger myCSharpTagger = new MyTagger(this.editor.SyntaxEditorElement);
editor.TaggersRegistry.RegisterTagger(myCSharpTagger);