Visual Studio MEF扩展-强制边距标志符号被更新或重绘 [英] Visual Studio MEF Extension - Force Margin Glyphs To Be Updated or Redraw

查看:96
本文介绍了Visual Studio MEF扩展-强制边距标志符号被更新或重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写的扩展程序从演练开始:创建Microsoft提供的边距标志符号示例: https://msdn.microsoft.com/en-us/library/ee361745.aspx

The extension I am writing started life from the Walkthrough: Creating a Margin Glyph example provided by Microsoft: https://msdn.microsoft.com/en-us/library/ee361745.aspx

一切正常,除了我试图在决定用于更改的哪条线绘制数据的数据时,我试图触发边距字形的重绘或更新.

Everything works fine, except I am trying to trigger the redrawing or updating of the margin glyphs whenever the data I use for deciding which line to draw a glyph on changes.

基本上,我在工具窗口中有一个按钮,当用户单击该按钮时,我希望字形出现在页边距中.现在,它不会出现,直到您前后滚动或明显关闭并重新加载文档为止.

Basically I have a button in a tool window, when the user clicks the button, I want a glyph to appear in the margin. Right now, it does not appear until you scroll away and back, or obviously close and reload the document.

我已经对此进行了研究,并且看到了一些使用IViewTaggerProvider而不是ITaggerProvider的代码示例.在这些情况下,似乎可以将LayoutChanged事件的处理程序添加到ITagger派生类中,该类也包含GetTags方法.但是,我无法成功地将代码从使用ITaggerProvider切换到IViewTaggerProvider,该扩展在运行时崩溃.我不知道这是否会导致解决方案的更改,或者是否不必要.

I have researched this, and have seen some code samples that use IViewTaggerProvider instead of ITaggerProvider. In those cases it appeared that a handler for a LayoutChanged event is able to be added to the ITagger derived class which also contains the GetTags method. However I was unable to successfully switch the code from using ITaggerProvider to IViewTaggerProvider, the extension crashed when run. I don't know if this is a change that will lead to the solution, or if it's unnecessary.

如何强制显示字形?我可以引发某种事件来强制执行GetTags代码吗?我将如何从课堂之外发起该事件?例如在工具窗口中?

How can I force the glyph to get rendered? Can I raise an event of some kind to force the GetTags code to be exercised? How would I raise that event from outside of the class? From the tool window for example?

推荐答案

您在正确的道路上,从ITaggerProvider更改为IViewTaggerProvider,使我可以重绘字形.我在演练:显示匹配括号示例以进行这些更改.

You were on the right path, changing from ITaggerProvider to IViewTaggerProvider allowed me to redraw the glyphs. I used the Implementing a Brace Matching Tagger Provider section in Walkthrough: Displaying Matching Braces example to make these changes.

使用IViewTaggerProvider,然后可以调用

Using the IViewTaggerProvider, you can then call

TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(
                              new SnapshotSpan(
                                      SourceBuffer.CurrentSnapshot,
                                      0, 
                                      SourceBuffer.CurrentSnapshot.Length)));

在函数中显式调用GetTag,并遍历当前快照中的跨度.

in your functions to explicitly call GetTags and go over the spans in the current snapshot.

这篇关于Visual Studio MEF扩展-强制边距标志符号被更新或重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆