Getting Started

This tutorial will walk you through the creation of a sample application that contains a RadSyntaxEditor control.

Assembly References

In order to use RadSyntaxEditor, you will need to add references to the following assemblies:

  • Telerik.Windows.Controls
  • Telerik.Windows.Controls.Input
  • Telerik.Windows.Controls.SyntaxEditor
  • Telerik.Windows.SyntaxEditor.Core

You can find the required assemblies for each control from the suite in the Controls Dependencies help article.

Defining RadSyntaxEditor

Example 1 demonstrates how you can define a RadSyntaxEditor in XAML.

Example 1: Defining RadSyntaxEditor

<telerik:RadSyntaxEditor x:Name="syntaxEditor" /> 

Figure 1: Empty RadSyntaxEditor

Empty RadSyntaxEditor

Opening a File

To load a file in the RadSyntaxEditor you need to use its Document property.

Example 2: Opening a File

public MainWindow() 
{ 
    InitializeComponent(); 
 
    using (StreamReader reader = new StreamReader("../../CS_File.txt")) 
    { 
        this.syntaxEditor.Document = new TextDocument(reader); 
    } 
} 

Figure 2: RadSyntaxEditor with a loaded C# file

RadSyntaxEditor with a loaded CS file

Enable Syntax Highlighting

Once you have loaded the code, you need to register an appropriate tagger to enable syntax highlighting for the particular language.

Example 3: Enable C# code highlighting

var cSharptagger = new CSharpTagger(this.syntaxEditor); 
this.syntaxEditor.TaggersRegistry.RegisterTagger(cSharptagger); 

Figure 3: RadSyntaxEditor with C# code highlighting

RadSyntaxEditor with C# code highlighting

See Also

In this article
Not finding the help you need? Improve this article