首页 文章

在VS11 Solution Explorer中预览文件

提问于
浏览
0

我有一个Visual Studio扩展,它生成一个脚本文件并将其添加到当前项目中 .

我想利用Visual Studio 2012解决方案资源管理器中的文件预览功能,以便在将文件添加到项目时(而不是实际打开文件)预览文件 .

这是我到目前为止的代码:

UIHierarchy UIH = ((DTE2)dte).ToolWindows.SolutionExplorer;
UIHierarchyItem UIHItem = UIH.GetItem(@"MySolution\MyProject\MyClass.cs");
UIHItem.Select(vsUISelectionType.vsUISelectionTypeSelect);

这将选择解决方案资源管理器中的项目,但不会导致显示预览 .

有没有办法让VS显示预览?

1 回答

  • 0

    我想出了一个解决方案,但它并不完美 .

    由于似乎没有显示文件预览的特定命令,因此可以选择两次“预览所选项目”按钮 .

    // Select the new item in the Solution Explorer
    UIHierarchy UIH = ((DTE2)dte).ToolWindows.SolutionExplorer;
    UIHierarchyItem UIHItem = UIH.GetItem(@"MySolution\MyProject\MyClass.cs");
    UIHItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
    
    var guidStandardCommandSet11 = new Guid("{D63DB1F0-404E-4B21-9648-CA8D99245EC3}");
    int cmdidToggleSingleClickPreview = 35;
    
    // Activate the Solution Explorer to ensure the following commands are available
    dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate(); 
    
    // Toggle the Preview button in the Solution Explorer on/off or off/on
    dte.Commands.Raise(guidStandardCommandSet11.ToString(), cmdidToggleSingleClickPreview, null, null);
    dte.Commands.Raise(guidStandardCommandSet11.ToString(), cmdidToggleSingleClickPreview, null, null);
    

    通过将其翻转两次,始终显示预览,并始终保持之前的切换状态(由用户设置) .

相关问题