【问题标题】:Preview file in VS11 Solution Explorer在 VS11 解决方案资源管理器中预览文件
【发布时间】:2012-08-06 08:16:40
【问题描述】:

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

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

这是我目前的代码:

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

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

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

【问题讨论】:

    标签: visual-studio-2012 visual-studio-addins vsx


    【解决方案1】:

    我想出了一个解决方案,但它并不完全漂亮。

    由于似乎没有显示文件预览的特定命令,因此另一种方法是切换“预览所选项目”按钮两次。

    // 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);
    

    通过切换两次,始终显示预览并始终保持先前的切换状态(由用户设置)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-20
      • 2019-03-24
      • 2013-11-20
      • 2016-12-11
      • 2018-06-07
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      相关资源
      最近更新 更多