在 VS 2010 RC 扩展中查找给定 ProjectItem 的 IVsTextView 或 IWpfTextView
我有 ProjectItem,并且想要获取与其关联的 IWPFTextView(如果有)。
我尝试获取 IVsTextManager,然后迭代视图,但 iVsTextManager.EnumViews 始终不返回任何内容。
这是我到目前为止所得到的:
var txtMgr = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
if (txtMgr != null)
{
IVsEnumTextViews iVsEnumTextViews;
IVsTextView[] views = null;
// Passing null will return all available views, at least according to the documentation
// unfortunately, this returns a 0x80070057 error (invalid parameter)
var errorValue = txtMgr.EnumViews(null, out iVsEnumTextViews);
if (errorValue == VSConstants.S_OK)
{
// enumerate, find the IVsTextView with a matching filename.
肯定还有另一种/更好的方法吗?
预先感谢
〜卡梅伦
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 views, but iVsTextManager.EnumViews always returns nothing.
Here is what I've got so far:
var txtMgr = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
if (txtMgr != null)
{
IVsEnumTextViews iVsEnumTextViews;
IVsTextView[] views = null;
// Passing null will return all available views, at least according to the documentation
// unfortunately, this returns a 0x80070057 error (invalid parameter)
var errorValue = txtMgr.EnumViews(null, out iVsEnumTextViews);
if (errorValue == VSConstants.S_OK)
{
// enumerate, find the IVsTextView with a matching filename.
Surely there is another/better way??
Thanks in advance
~ Cameron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是具体操作方法。首先获取项目项的完整路径,然后调用此帮助器方法:
Here is how to do it. First get the full path for the project item, then call this helper method:
我知道这个问题已经有一段时间了,但希望以下用于从 IVsTextView 检索 IWpfTextView 的代码将对其他人有所帮助:
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:
你可以这样获取 IWpfTextView:
You can get IWpfTextView like that: