C#的滚动条装饰?

问题描述 投票:1回答:1

当写一个Visual Studio扩展,有没有什么办法来影响它如何呈现地图模式滚动条为C#?

enter image description here

c# visual-studio adornment
1个回答
4
投票

我没有时间完整的答案,但因为旁边一下零的信息在网络上有,我会写短之一:

  1. 创建VSIX解决方案。
  2. 添加项目,并在“可扩展性”类别中选择“编辑保证金”
  3. 在一本被alonside保证金文件创建后你是第2步设置以下行“[yourEditorMarginName] Factory.cs”文件: [MarginContainer(PredefinedMarginNames.VerticalScrollBar)] [Order(Before = PredefinedMarginNames.LineNumber)]
  4. 返回到“[yourEditorMarginName]的.cs”文件。请确保您删除在构造以下行: this.Height = 20; this.ClipToBounds = true; this.Width = 200;
  5. 现在,你收到了参考IWpfTextView在构造函数中,注册其OnLayoutChanged事件(或使用适合你一些其他事件): TextView.LayoutChanged += OnLayoutChanged;
  6. 在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);
  7. 这里是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; }
  8. 是啊ScrollBar变量是你可以得到这样说: public ScrollbarMargin(IWpfTextView textView, IWpfTextViewMargin marginContainer/*, MarginCore marginCore*/) { ITextViewMargin scrollBarMargin = marginContainer.GetTextViewMargin(PredefinedMarginNames.VerticalScrollBar); ScrollBar = (IVerticalScrollBar)scrollBarMargin;
© www.soinside.com 2019 - 2024. All rights reserved.