[英]Visual Studio Extensibility: Rectange-s added to Children class of the ScrollbarMargin prevent mouse clicks on the scrollbar
I've developed an extension some time ago that allows to highlight a section of the scrollbar with the specified color, here is how I do it:前段时间我开发了一个扩展,它允许用指定的颜色突出显示滚动条的一部分,这是我的做法:
/// <summary>On layout changed analyze the regions and lines and highlight them on the scroll bar if needed.</summary>
private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
Children.Clear();
int n = AllAdornments.TextAdornment.Regions.Length;
for (int i = 0; i < n; i++)
{
if (AllAdornments.TextAdornment.Regions[i].Adornment != null
&& AllAdornments.TextAdornment.Regions[i].EndLine < e.NewSnapshot.LineCount)
{
var rect = new Rectangle();
var firstLine = e.NewSnapshot.GetLineFromLineNumber(AllAdornments.TextAdornment.Regions[i].StartLine);
var lastLine = e.NewSnapshot.GetLineFromLineNumber(AllAdornments.TextAdornment.Regions[i].EndLine);
double top, bottom;
double firstLineTop;
MapLineToPixels(firstLine, out firstLineTop, out bottom);
SetTop(rect, firstLineTop);
SetLeft(rect, ScrollBarLeftPadding);
MapLineToPixels(lastLine, out top, out bottom);
rect.Height = bottom - firstLineTop;
rect.Width = ScrollBarWidth;
Color color = Communicator.LerpColor(AllAdornments.TextAdornment.UserBackgroundCol,
AllAdornments.TextAdornment.Regions[i].Adornment.Color, ScrollBarIntensity
* AllAdornments.TextAdornment.Regions[i].Adornment.IntensityMult);
color.A = ScrollBarOpacity;
rect.Fill = new SolidColorBrush(color);
Children.Add(rect);
}
}
}
Here is how it looks in Visual Studio:下面是它在 Visual Studio 中的样子:
This worked perfectly for a long time (around 1,5 - 2 years), but when I updated VS four months ago a problem emerged: I can no longer click on the section of the scrollbar margin with the colored Rectangle - the mouse click simply does nothing as long as it is above the colored Rectangle.这在很长一段时间(大约 1,5 - 2 年)都运行良好,但是当我四个月前更新 VS 时出现了一个问题:我无法再单击带有彩色矩形的滚动条边距部分 - 鼠标单击只要它在彩色矩形上方,什么都不做。 On the empty section of the scrollbar it works as usual.
在滚动条的空白部分,它照常工作。 Before I could not only click on my Rectangle-s, but hold the mouse button down and drag the scrollbar.
之前我不仅可以单击我的 Rectangle-s,还可以按住鼠标按钮并拖动滚动条。 Is there any way I can bring back this functionality?
有什么办法可以恢复这个功能吗?
你可以尝试设置 rect.IsHitTestVisible = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.