WPF RichTextBox to create editor with line numbers [closed] WPF RichTextBox to create editor with line numbers [closed] wpf wpf

WPF RichTextBox to create editor with line numbers [closed]


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.enter image description 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.