TextAnchor Class
The TextAnchor class references an offset (a position between two characters). It automatically updates the offset when text is inserted/removed in front of the anchor.
Declaration Syntax
C#Visual BasicVisual C++
public sealed class TextAnchor : ITextAnchor
Public NotInheritable Class TextAnchor _
	Implements ITextAnchor
public ref class TextAnchor sealed : ITextAnchor
All MembersMethodsPropertiesEvents

Gets the column number of this anchor.

Occurs after the anchor was deleted.

Gets the document owning the anchor.

Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Serves as a hash function for a particular type.
(Inherited from Object.)
Gets the Type of the current instance.
(Inherited from Object.)
Gets whether the anchor was deleted.

Gets the line number of the anchor.

Gets the text location of this anchor.

Controls how the anchor moves.

Gets the offset of the text anchor.


Specifies whether the anchor survives deletion of the text containing it.

false: The anchor is deleted when the a selection that includes the anchor is deleted. true: The anchor is not deleted.

Returns a String that represents the current Object.
(Overrides Object.ToString()()()().)

Use the Offset property to get the offset from a text anchor. Use the CreateAnchor(Int32) method to create an anchor from an offset.

The document will automatically update all text anchors; and because it uses weak references to do so, the garbage collector can simply collect the anchor object when you don't need it anymore.

Moreover, the document is able to efficiently update a large number of anchors without having to look at each anchor object individually. Updating the offsets of all anchors usually only takes time logarithmic to the number of anchors. Retrieving the Offset property also runs in O(lg N).

When a piece of text containing an anchor is removed, then that anchor will be deleted. First, the IsDeleted property is set to true on all deleted anchors, then the Deleted events are raised. You cannot retrieve the offset from an anchor that has been deleted.

This deletion behavior might be useful when using anchors for building a bookmark feature, but in other cases you want to still be able to use the anchor. For those cases, set SurviveDeletion = true.

Anchor movement is ambiguous if text is inserted exactly at the anchor's location. Does the anchor stay before the inserted text, or does it move after it? The property MovementType will be used to determine which of these two options the anchor will choose. The default value is Default.

If you want to track a segment, you can use the AnchorSegment class which implements ISegment using two text anchors.

 Copy imageCopy
TextAnchor anchor = document.CreateAnchor(offset);
            int newOffset = anchor.Offset;
Inheritance Hierarchy

Assembly: ICSharpCode.AvalonEdit (Module: ICSharpCode.AvalonEdit.dll) Version: