我没有时间给出完整的答案,但我会写一个简短的答案,因为网上关于它的信息几乎为零:
在执行步骤 2 后与边距文件一起创建的“[yourEditorMarginName]Factory.cs”文件中,设置以下行:
[MarginContainer(PredefinedMarginNames.VerticalScrollBar)]
[Order(Before = PredefinedMarginNames.LineNumber)]
Run Code Online (Sandbox Code Playgroud)返回“[yourEditorMarginName].cs”文件。确保在构造函数中删除以下行:
this.Height = 20;
this.ClipToBounds = true;
this.Width = 200;
Run Code Online (Sandbox Code Playgroud)现在您在构造函数内收到了对 IWpfTextView 的引用,注册其 OnLayoutChanged 事件(或使用适合您的其他一些事件):
TextView.LayoutChanged += OnLayoutChanged;
Run Code Online (Sandbox Code Playgroud)在OnLayoutChanged中,您可以执行以下操作来添加矩形装饰:
var rect = new Rectangle();
double bottom;
double firstLineTop;
MapLineToPixels([someLineYouNeedToHighlight], out firstLineTop, out bottom);
SetTop(rect, firstLineTop);
SetLeft(rect, 0);
rect.Height = bottom - firstLineTop;
rect.Width = [yourWidth];
Color color = [your Color];
rect.Fill = new SolidColorBrush(color);
Children.Add(rect);
Run Code Online (Sandbox Code Playgroud)这是 MapLineToPixels():
private void MapLineToPixels(ITextSnapshotLine line, out double top, out double bottom)
{
double mapTop = ScrollBar.Map.GetCoordinateAtBufferPosition(line.Start) - 0.5;
double mapBottom = ScrollBar.Map.GetCoordinateAtBufferPosition(line.End) + 0.5;
top = Math.Round(ScrollBar.GetYCoordinateOfScrollMapPosition(mapTop)) - 2.0;
bottom = Math.Round(ScrollBar.GetYCoordinateOfScrollMapPosition(mapBottom)) + 2.0;
}
Run Code Online (Sandbox Code Playgroud)是的,ScrollBar变量可以通过以下方式获得:
public ScrollbarMargin(IWpfTextView textView, IWpfTextViewMargin marginContainer/*, MarginCore marginCore*/)
{
ITextViewMargin scrollBarMargin = marginContainer.GetTextViewMargin(PredefinedMarginNames.VerticalScrollBar);
ScrollBar = (IVerticalScrollBar)scrollBarMargin;
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
967 次 |
| 最近记录: |