I found an example, how to show the LineNumbers from a RichTextBox
in Windows Forms.
http://www.codeproject.com/Articles/38858/Line-Numbers-for-RichText-Control-in-C
Have somebody an example for it in WPF?
Edit:
Does someone have work with AvalonEdit, because he wanted to show LineNumbers in his Programm and can help me by my Problem.
I thought just to add a simple solution...
Avalon
(Download) has been mentioned, here is how to do row lines with it:It's a very powerful editor - and I've been doing a lot with it and in production (custom language compilers etc.). It's free so it has its 'quirks' but it's allowing you to do pretty much anything you need. I'm not sure which formatted text are you talking about - but anything you need can be done, and in not too many lines of code, if you know how, where to inject (you can add your own generators, transformers, pretty much any visuals, code completition etc. - and I have no vested interest in it:)
Edit
Small sample for syntax highlighting:
Supported is
"XmlDoc", "C#", "JavaScript", "HTML", "ASP/XHTML", "Boo", "Coco", "CSS", "C+", "Java", "Patch", "PHP", "TeX", "VBNET", "XML"
as far as I can tell from the code.If you'd like to implement your own custom
syntax highlighting
(Avalon editor is highly extendable - for details see that code project article mentioned)...You'd need to define your own
IHighlightingDefinition
, then register that with theHighlightingManager
from the code - and then add some more things to complement. But that's a long story on its own.ScintillaNET is a good component to try. It's the .NET version of Scintilla which is a key component in the Notepad++ editor (among others). I don't know how it compares to AvalonEdit, but I found it fairly easy to implement in my code and it has the feature you require (and many more).
Once you've installed the component and added it to your form, you can show line numbers by going to the properties of the control and setting Margins>Margin0>Width. You can also set this programmatically:
You might find the ScintillaNet documentation useful if you plan to take this route - I found it really helpful when I started.
Here's a nice CodeProject article that shows a detailed approach to implementing line numbers and a handful of other nice code editing features in a TextBox control. If you don't care about how it's built, just download the sample file and use the included dll that contains the compiled control.
Just use a custom template for your TextBox; the following answer may help you:
Visible line count of a TextBlock
Update
Changing the answer to get works as OP expected.
Designer,
Attached property,
The best example you can find is in AvalonEdit. There is lot more anyway that just line numbering, but you can study how it is done, code is very clear. A staring point to see what we are talking about can be this CodeProject article.