WPF RichTextBox to create editor with line numbers [closed]

假如想象 提交于 2019-11-29 09:17:27

AvalonEdit is a good one, and it's open source. I think it has nearly all of the features of the Aqistar control such as syntax highlighting and folding. Ease to configure and use. Further details can be found here.

I would create a composite control, with a stack panel control and text blocks on the left which you would use to handle the line numbering. If you are concerned with the number of lines and having too many visual elements, then you could use a ListBox in virtual mode.

You would have to hook up to the various events on the RichTextBox so that you know when to update the ListBox, as well as calculate the height of each line, but that should be doable with the FlowDocument attached to the RichTextBox.

RichText supports "protected" - uneditable - spans. You could dump your line numbers as protected text spans as a part of the RTF stream (when you do your formatting).

In Win Forms, you can use RichTextBox.SelectionProtected Property. WPF must have something similar.

This way, all your baselines will be correct and you won't have to do any extra thinking/programming to get the editor to behave properly. Editable text will be editable, and line numbers will not be.

Only down side is that you have to resubmit the RTF stream after every edit. But I imagine you were already doing this to provide parse formatting / error diagnostics / whatever.

How about using AqiStar's rich text WPF control? AqiStar.TextBox

I don't work for them...I just know that Oren is using this product in his NHibernate Profiler (NHProf) and he seems to dig it.

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