我正在尝试使在后面的代码中定义的特定可见行(例如 line152)成为 TextView 上的第一个可见行。另外,我希望突出显示这一行。到目前为止,我已经实施了以下解决方案,没有缺乏:
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
为了突出显示这一行,我找到了一个 Draw() 函数,但不知道如何调用它:
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
);
}
}