2

I need to show popup use TextViewAdornment, it's require IWpfTextView. There is old code to that:

private IWpfTextView GetWpfTextView(IVsTextView vTextView)
{
   IWpfTextView view = null;
   IVsUserData userData = vTextView as IVsUserData;

   if (null != userData)
   {
      IWpfTextViewHost viewHost;
      object holder;
      Guid guidViewHost = DefGuidList.guidIWpfTextViewHost;
      userData.GetData(ref guidViewHost, out holder);
      viewHost = (IWpfTextViewHost)holder;
      view = viewHost.TextView;
   }
   return view;
}

but when go to Visual studio 2017 Extension DefGuidList.guidIWpfTextViewHost is missing. So I cannot get IWpfTextView anymore.

Please help me. Thank you everyone.

Tan Nguyen
  • 91
  • 6
  • See https://stackoverflow.com/a/41215263/84507 – Sergey Vlasov Aug 19 '17 at 06:09
  • Thank you so much! – Tan Nguyen Aug 19 '17 at 13:44
  • For other people: you must add reference manual. Add Reference -> Assemblies -> Extensions then choose Microsoft.VisualStudio.ComponentModelHost and Microsoft.VisualStudio.Editor – Tan Nguyen Aug 19 '17 at 14:56
  • @Tan Nguyen, So this issue has been resolved, am I right? If so, would you please post the solution as an answer? So you could mark it as the answer later and help other community members who get the same issue as yours. – Jack Zhai Aug 21 '17 at 11:59

1 Answers1

4

After Sergey Vlasov answer I found a solution:

private IWpfTextView GetWpfView()
{
        var textManager = (IVsTextManager)ServiceProvider.GetService(typeof(SVsTextManager));
        var componentModel = (IComponentModel)this.ServiceProvider.GetService(typeof(SComponentModel));
        var editor = componentModel.GetService<IVsEditorAdaptersFactoryService>();

        textManager.GetActiveView(1, null, out IVsTextView textViewCurrent);
        return editor.GetWpfTextView(textViewCurrent);
}

You must add some reference manual by Add Reference -> Assemblies -> Extensions. Then choose:

 Microsoft.VisualStudio.ComponentModelHost 
 Microsoft.VisualStudio.Editor
Tan Nguyen
  • 91
  • 6