我正在尝试使一个特定的可见行(例如,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
);
}
}发布于 2013-11-11 19:31:27
对于整理,请使用:
double visualTop = textEditor.TextArea.TextView.GetVisualTopByDocumentLine(line);
textEditor.ScrollToVerticalOffset(visualTop);为了突出显示,创建一个实现IBackgroundRenderer接口的新类。然后将类的一个实例添加到textEditor.TextArea.TextView.BackgroundRenderers集合中。
https://stackoverflow.com/questions/19887868
复制相似问题