Margins

The RadSyntaxEditor control contains several panels inside its ControlTemplate, which allow for customizing its look and/or extending its functionality. In order to customize them you can use the Margins property, which is of type SyntaxEditorMargins.

Margin Panels

Example 1 demonstrates how you can add some custom elements around the RadSyntaxEditor and provides a visualization of the default locations for all panels. It also demonstrates the line numbers and folding taggger features, which are implemented with the help of the left scrollable margin.

Example 1: Defining the RadSyntaxEditor

<Grid xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"> 
    <telerik:RadSyntaxEditor x:Name="syntaxEditor" /> 
</Grid> 

Example 1: Defining the RadSyntaxEditor

public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
        InitializeComponent(); 
 
        using (StreamReader reader = new StreamReader("../../Files/MainWindow.xaml.cs")) 
        { 
            this.syntaxEditor.Document = new TextDocument(reader); 
        } 
 
        var foldingTagger = new CSharpFoldingTagger(this.syntaxEditor); 
        this.syntaxEditor.TaggersRegistry.RegisterTagger(foldingTagger); 
 
        this.syntaxEditor.Margins.Left.Add(new Rectangle() { Fill = Brushes.Yellow, Width = 20 }); 
        this.syntaxEditor.Margins.Right.Add(new Rectangle() { Fill = Brushes.Green, Width = 20 }); 
        this.syntaxEditor.Margins.Top.Add(new Rectangle() { Fill = Brushes.Red, Height = 20 }); 
        this.syntaxEditor.Margins.Bottom.Add(new Rectangle() { Fill = Brushes.Brown, Height = 20 }); 
        this.syntaxEditor.Margins.ScrollableLeft.Add(new Rectangle() { Fill = Brushes.Brown, Width = 20 }); 
        this.syntaxEditor.Margins.ScrollableRight.Add(new Rectangle() { Fill = Brushes.Purple, Width = 20 }); 
        this.syntaxEditor.Margins.ScrollableTop.Add(new Rectangle() { Fill = Brushes.Pink, Height = 20 }); 
        this.syntaxEditor.Margins.ScrollableBottom.Add(new Rectangle() { Fill = Brushes.Black, Height = 20 }); 
    } 
} 

Figure 1: RadSyntaxEditor Margins

RadSyntaxEditor Margins

See Also

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