question

Minuri89-7632 avatar image
0 Votes"
Minuri89-7632 asked Minuri89-7632 commented

Add a glyph icon to a new margin in vsix C# project

I have added a new margin to my VSIX project referring Microsoft documentation https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.iwpftextviewmarginprovider.createmargin?view=visualstudiosdk-2019

Now I am stuck with adding a glyph icon to the newly created margin. As per the below image, my intent is to move the glyph icon from the margin where it exists currently to the newly created margin.

109388-image.png



     [Export(typeof(IGlyphFactoryProvider))]
     [Name("TodoGlyph")]
     [Order(After = "EditorMargin2")]
     [ContentType("code")]
     [TagType(typeof(TodoTag))]
     [MarginContainer(PredefinedMarginNames.VerticalScrollBar)]
     internal sealed class TodoGlyphFactoryProvider : IGlyphFactoryProvider
     {
         public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
         {
             return new TodoGlyphFactory();
         }
     }


dotnet-csharpvs-extensions
image.png (68.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TianyuSun-MSFT avatar image
0 Votes"
TianyuSun-MSFT answered Minuri89-7632 commented

Hi @Minuri89-7632 ,

Welcome to Microsoft Q&A forum.

Does change this parameter: IWPfTextViewMargin(margin) work?

 public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
 {
     return new TodoGlyphFactory();
 }

IGlyphFactoryProvider.GetGlyphFactory(IWpfTextView, IWpfTextViewMargin) Method.

Best Regards,
Tianyu


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TianyuSun-MSFT ,

Thank you for the reply.

I have tried out below. But it doesn't make any cense because still the glyph icon is adding to the default margin. Please let me know, if I missed anything.

      [Export(typeof(IGlyphFactoryProvider))]
      [Name("Test_TextView_M")]
      [Order(After = "VsTextMarker")]
      [ContentType("code")]
      [TagType(typeof(TodoTag))]
      internal sealed class TodoGlyphFactoryProvider : IGlyphFactoryProvider
      {
          public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
          {
              margin = new TodoMargin(view);
              return new TodoGlyphFactory(margin);
          }
      }

Thanks!

0 Votes 0 ·