我有一个Visual Studio扩展,它生成一个脚本文件并将其添加到当前项目中。
我希望利用Visual Studio 2012解决方案资源管理器中的文件预览功能,以便在将文件添加到项目时进行预览(而不是实际打开文件)。
这是我到目前为止所拥有的代码:
UIHierarchy UIH = ((DTE2)dte).ToolWindows.SolutionExplorer;
UIHierarchyItem UIHItem = UIH.GetItem(@"MySolution\MyProject\MyClass.cs");
UIHItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
这将在“解决方案资源管理器”中选择该项,但不会导致显示预览。
有没有办法要求VS显示预览?
发布于 2012-08-07 14:33:21
我已经想出了一个解决方案,但它并不是很好。
由于似乎没有特定的命令来显示文件预览,另一种方法是切换两次“预览选定项目”按钮。
// 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);
通过切换两次,预览将始终显示,并且始终保持先前的切换状态(由用户设置)。
https://stackoverflow.com/questions/11824701
复制相似问题