Custom Margins

The TextArea contains a LeftMargins collection. By default, this contains the LineNumberMargin (if enabled). You can add your own controls to this collection to create features like breakpoints, bookmarks, or git diff indicators.

Creating a Margin

A margin is simply a Control that implements ITextViewConnect (optional, but recommended for wiring up events).

public class MyMargin : Control, ITextViewConnect
{
    public TextView TextView { get; set; }

    public void AddToTextView(TextView textView)
    {
        TextView = textView;
        // Hook up events like VisualLinesChanged to redraw
    }

    public void RemoveFromTextView(TextView textView)
    {
        TextView = null;
    }

    public override void Render(DrawingContext context)
    {
        // Custom drawing logic here
    }
}

Adding the Margin

var margin = new MyMargin();
editor.TextArea.LeftMargins.Insert(0, margin); // Insert at far left

See the CustomMargin class in the Demo project for a full implementation of a breakpoint-style margin.