VS11解决方案资源管理器中的预览文件
问题描述:
我有一个Visual Studio扩展,它生成一个脚本文件并将其添加到当前项目中。VS11解决方案资源管理器中的预览文件
我想利用Visual Studio 2012解决方案资源管理器中的文件预览功能,以便在将文件添加到项目(而不是实际打开文件)时预览该文件。
这是我到目前为止的代码:
UIHierarchy UIH = ((DTE2)dte).ToolWindows.SolutionExplorer;
UIHierarchyItem UIHItem = UIH.GetItem(@"MySolution\MyProject\MyClass.cs");
UIHItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
这将选择在Solution Explorer但它不会导致显示预览的项目。
有什么办法可以让VS显示预览吗?
答
我想出了一个解决方案,但它不完全漂亮。
由于似乎没有显示文件预览的特定命令,因此可以选择两次切换“预览所选项目”按钮。
// 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);
通过翻转两次,预览总是显示与现有切换状态(由用户设定)始终保持。