Question

What is a robust way of making certain lines readonly in an AvalonEdit control? Users are allowed to change certain method bodies in a C# or VB template file but nothing else. The readonly state per line needs to be kept intact when users add or remove lines, i.e. the readonly blocks below the edited content need to shift up and down accordingly.

I'm using AvalonEdit in a WPFHost on winforms.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top