Visual Studio MEF Extension - Force Margin Glyphs To Be Updated or Redraw

别说谁变了你拦得住时间么 提交于 2019-12-30 08:17:10

问题


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.

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.

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?


回答1:


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.

Using the IViewTaggerProvider, you can then call

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

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



来源:https://stackoverflow.com/questions/36760891/visual-studio-mef-extension-force-margin-glyphs-to-be-updated-or-redraw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!