我没有时间完整的答案,但因为旁边一下零的信息在网络上有,我会写短之一:
[MarginContainer(PredefinedMarginNames.VerticalScrollBar)]
[Order(Before = PredefinedMarginNames.LineNumber)]
this.Height = 20;
this.ClipToBounds = true;
this.Width = 200;
TextView.LayoutChanged += 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);
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;
}
ScrollBar
变量是你可以得到这样说:
public ScrollbarMargin(IWpfTextView textView, IWpfTextViewMargin marginContainer/*, MarginCore marginCore*/)
{
ITextViewMargin scrollBarMargin = marginContainer.GetTextViewMargin(PredefinedMarginNames.VerticalScrollBar);
ScrollBar = (IVerticalScrollBar)scrollBarMargin;