New to Telerik UI for WPF? Download free 30-day trial

Caret & Caret Factory

RadRichTextBox has its own custom caret logic that is responsible for the caret functionality inside the RadDocument. It specifies the current position in the document and also allows you to modify the text. The control allows allows you to customize the default behavior via the Caret class and the ICaretFactory interface.


The Caret class represents the caret in the RadDocument object. It exposes the following API:

  • Text—Gets or sets the text contents of the text box, with all new lines removed.
  • InputState—Provides information about the input state of the caret. It is of the type of InputStates, which has Standard and Ime as options.
  • CaretBaseLineOffset—Returns the value of the base line offset of the caret.
  • IsBlinking—Gets or sets a value indicating whether the caret is blinking.
  • EnableAsynchronousTextInsertion—Controls whether or not the text should be added asynchronously to the RadDocument when typing fast.
  • MinimumTextInsertedInterval—Gets or sets the minimum interval (in milliseconds) between two consecutive raises of the caret's TextInserted event. The value is respected only when the EnableAsynchronousTextInsertion is set to true. The default value is 15.
  • LastInputEvent—Provides information about the last input event that was raised when performing text operations. The property is of the type of InputEvents enumeration and the available types of the input events are OnTextInputStart, OnTextInputUpdate, and OnTextInput. For more information about the input events, check this section.
  • ShouldStartNewComposition—This property identifies if a new text composition should be started.
  • ShouldPersist—This property carries the information if the composition text should be persisted.

The following example showcases how to disable asynchronous text addition when typing fast:

Creating a custom caret

public class MyCaret : Caret 
    public MyCaret() 
        : base() 
        this.EnableAsynchronousTextInsertion = false; 

Caret Factory

RadRichTextBox allows you to define a custom caret factory. To do so, create a class and implement the ICaretFactory interface. This factory is used to return a new instance of your custom Caret class via the CreateCaret method. To set it on the RadRichTextBox instance, use its CaretFactory property.

Creating a custom caret factory

public class MyCaretFactory : ICaretFactory 
    public Caret CreateCaret() 
        return new MyCaret(); 

Setting the custom caret factory to the RadRichTextBox control

this.radRichTextBox.CaretFactory = new MyCaretFactory(); 

You can find a runnable project with a customization to the caret functionality of the RadRichTextBox control in our SDK repository. Additionally, you can view it in our SDK Samples Browser application under the name Custom Caret.

In this article