Making (and keeping) lines readonly in AvalonEdit

≡放荡痞女 提交于 2019-12-13 02:23:03

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14416854/making-and-keeping-lines-readonly-in-avalonedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!