8

每个人都在设计模式下使用“属性”窗口。当我们切换到代码视图时,我们不需要属性窗口。

从设计视图进入代码视图时是否可以自动隐藏属性窗口?

4

1 回答 1

2

对于 vs2015:(也是 vs2017)

  1. 菜单 > 工具 > 扩展和更新
  2. 安装“视觉指挥官”。(现在您有了名为“VCmd”的新菜单)
  3. Menu > "VCmd" > Extensions ...(您将在右侧看到一个扩展窗格)
  4. 在扩展窗格中按添加按钮。(新标签窗口将打开。)
  5. 写一个扩展名。
  6. 选择语言为 C#。
  7. 粘贴以下代码:
  8. 按保存。然后按编译。然后按安装

edit2:代码适用于 c# winforms + xamarin.android 项目。

using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
using System;

public class E: VisualCommanderExt.IExtension {
   private EnvDTE80.DTE2 DTE;
   private EnvDTE.WindowEvents windowEvents;

   public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) {
      this.DTE = DTE;
      DTE.Events.WindowEvents.WindowActivated += OnWindowActivated;
   }

   public void Close() {
      // DTE.Events.WindowEvents.WindowActivated -= OnWindowActivated;
   }

   private void OnWindowActivated(Window gotFocus, Window lostFocus) {
      //project_details();
      HidePropertiesWindowInCodeOrTextView(gotFocus);

    }

   public void HidePropertiesWindowInCodeOrTextView(Window gotFocus) {
      //System.Windows.MessageBox.Show(  gotFocus.Document.Name +"" );

      if (gotFocus.Document == null) return;
      var pwin = DTE.Windows.Item(Constants.vsWindowKindProperties);

      if (isAndroidProject()) 
      {
        pwin.AutoHides = !gotFocus.Caption.EndsWith(".axml");
      }else
      {
        pwin.AutoHides = !gotFocus.Caption.EndsWith(" [Design]");
      }

      //pwin.AutoHides = true;  // pwin.Activate();
   }

   public bool isAndroidProject() {
      if (DTE == null || DTE.ActiveWindow == null) return false;
      var cp = DTE.ActiveWindow.Project;
      var AndroidApp = System.IO.File.ReadAllText(cp.FullName).Contains("AndroidApplication");
      return AndroidApp;
   }

   // for debug , window,document names
   public void project_details() {
      try {
         if (DTE == null || DTE.ActiveWindow == null) return;

         var cp = DTE.ActiveWindow.Project;
         var ad = DTE.ActiveDocument; //Name Kind
         var av = DTE.ActiveWindow; // Caption Kind
         if (cp == null) return;

         var msgp = "aProj:" + (cp != null ? cp.FullName: "[no project for Window]") + "\r\n" 
         + "aDoc: " + ad.Name + ", " + ad.Kind + "\r\n" 
         + "aWin: " + av.Caption + ", " + av.Kind;

         MessageBox.Show(msgp, "ert4 -anbdapp" + isAndroidProject() );

      } catch(Exception ex) {
         MessageBox.Show(ex + "");
      }

   }




}
于 2017-11-29T13:50:15.617 回答