Visual Studio 扩展性:Rectangle-被添加到滚动条边距的子 class 防止鼠标点击滚动条

Visual Studio Extensibility: Rectange-s added to Children class of the ScrollbarMargin prevent mouse clicks on the scrollbar

前段时间我开发了一个扩展程序,可以用指定的颜色突出显示滚动条的一部分,我是这样做的:

/// <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);
            }
        }
   }

下面是它在 Visual Studio 中的样子:

这在很长一段时间内(大约 1.5 - 2 年)都运行良好,但是当我四个月前更新 VS 时出现了一个问题:我无法再单击带有彩色矩形的滚动条边距部分- 只要在彩色矩形上方单击鼠标,它就不会执行任何操作。在滚动条的空白部分,它照常工作。之前我不仅可以单击我的 Rectangle-s,还可以按住鼠标按钮并拖动滚动条。有什么办法可以恢复此功能吗?

你可以尝试设置 rect.IsHitTestVisible = false;