Find an IVsTextView or IWpfTextView for a given ProjectItem, in VS 2010 RC extension

前端 未结 3 1824
一向
一向 2020-12-05 19:46

I have the ProjectItem, and want to get the IWPFTextView that is associated with it, if any.

I have tried to get an IVsTextManager, and then iterate through the view

3条回答
  •  北海茫月
    2020-12-05 20:25

    I know it has been a while since this question has been answered, but hopefully the following code for retrieving the IWpfTextView from the IVsTextView will help someone else:

    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;
    }
    

提交回复
热议问题