简体   繁体   English

Visual Studio 扩展性:添加到 ScrollbarMargin 的 Children 类的 Rectange-s 可防止鼠标在滚动条上单击

[英]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.

相关问题 我可以在Visual Studio可扩展性中以编程方式添加新的命名命令吗? - Can I programatically add a new named command in visual studio extensibility? Visual Studio可扩展性:如何控制组件的加载顺序? - Visual Studio Extensibility: How to control the loading order of components? Visual Studio 2013可扩展性VSIX项目模板在哪里 - Where is Visual Studio 2013 Extensibility VSIX Project Template 访问VS语言服务(Visual Studio可扩展性)中的其他文件 - Access other files in VS Language Service (Visual Studio Extensibility) 我在 Visual Studio 2013 的可扩展性选项卡中找不到添加自定义命令选项 - I am not finding the add custom command option in the extensibility tab of Visual Studio 2013 Visual Studio SDK-处理鼠标事件以获取利润 - Visual Studio SDK - Handle mouse events for margins 如何在Visual Studio中以编程方式对VSIX软件包添加的菜单项进行排序? - How to sort programmatically menu items added by VSIX Package in Visual Studio? 将现有的类库打包为Visual Studio扩展 - Packaging existing Class Library as a Visual Studio Extension Visual Studio 扩展鼠标按钮事件不起作用 - Visual Studio Extension Mouse Button events not working 在 Visual Studio 扩展中添加/删除的监视器类 - Monitor classes added/removed in Visual Studio extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM