You can set textEditor.TextArea.ReadOnlySectionProvider
to an implementation of IReadOnlySectionProvider
.
AvalonEdit contains the implementation TextSegmentReadOnlySectionProvider
which allows marking segments as read-only. These read-only segments will move around when the user adds/inserts text.
TextSegmentReadOnlySectionProvider
doesn't allow you to prevent insertions at the very beginning and end of the document (as those positions are never are within any segment), but you can inherit from the class and override CanInsert()
to fix this special case.