I am trying to to make a specific visible line (e.g. line152), which is defined in code behind, to become a First visible line on TextView. Also, I would like this line to be highlighted. So far I have the implemented the following solution, without lack:
textEditor.ScrollTo(myLine, 0); // Setting the current line Visible (e.g. line152) in TextView
int firstLine = textEditor.TextArea.TextView.GetDocumentLineByVisualTop(textEditor.TextArea.TextView.ScrollOffset.Y).LineNumber; // This is actual top visible line of current TextView ((e.g. line130)
textEditor.ScrollTo(firstLine - myLine, 0); //Which is not working
For Highlighting this line I found a Draw() function but not sure how to invoke it:
public void Draw(TextView textView, DrawingContext drawingContext)
{
textView.EnsureVisualLines();
var line = textEditor.Document.GetLineByOffset(textEditor.CaretOffset);
var segment = new TextSegment { StartOffset = line.Offset, EndOffset = line.EndOffset };
foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, segment))
{
drawingContext.DrawRoundedRectangle(
new SolidColorBrush(Color.FromArgb(20, 0xff, 0xff, 0xff)),
new Pen(new SolidColorBrush(Color.FromArgb(30, 0xff, 0xff, 0xff)), 1),
new Rect(r.Location, new Size(textView.ActualWidth, r.Height)),
3, 3
);
}
}