I achieve a "result" thinking about a list and the RichEditBox. Now, the solution isn't good, after about 50 lines typing it's laggy as hell, but at least I tried, 'cos the question is important also for me.
So, I designed a ListView and RichEditBox in a Grid with two columns
<ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" Name="LineNumbers" ScrollViewer.VerticalScrollMode="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"></ListView>
<RichEditBox Grid.Column="1" x:Name="RebText" TextChanged="RebText_TextChanged" ScrollViewer.VerticalScrollMode="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"></RichEditBox>
</Grid>
</ScrollViewer>
At the code behind I added this one:
private void RebText_TextChanged(object sender, RoutedEventArgs e)
{
//Clear line numbers
LineNumbers.Items.Clear();
int i = 1;
//Get all the thext
ITextRange text = RebText.Document.GetRange(0, TextConstants.MaxUnitCount);
string s = text.Text;
if (s != "\r")
{
//Replace return char with some char that will be never used (I hope...)
string[] tmp = s.Replace("\r", "§").Split('§');
foreach (string st in tmp)
{
//String, adding new line
if (st != "")
{
LineNumbers.Items.Add(i++);
}
//No string, empty space
else
{
LineNumbers.Items.Add("");
}
}
}
}
I think the .clear() method and readding all the lines every time is n't a good practice. But if you need a quick solution on max 50 lines, this MAYBE is the way.