首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AvalonEdit TextView滚动

AvalonEdit TextView滚动
EN

Stack Overflow用户
提问于 2013-11-10 16:51:09
回答 1查看 2K关注 0票数 0

我正在尝试使一个特定的可见行(例如,line152)成为TextView上的第一个可见行,它在后面的代码中定义。另外,我想要突出显示这一行。到目前为止,我已经实现了以下解决方案,不乏以下几点:

代码语言:javascript
复制
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()函数,但不确定如何调用它:

代码语言:javascript
复制
 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
            );
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2013-11-11 19:31:27

对于整理,请使用:

代码语言:javascript
复制
    double visualTop = textEditor.TextArea.TextView.GetVisualTopByDocumentLine(line);
    textEditor.ScrollToVerticalOffset(visualTop);

为了突出显示,创建一个实现IBackgroundRenderer接口的新类。然后将类的一个实例添加到textEditor.TextArea.TextView.BackgroundRenderers集合中。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19887868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档