Reputation: 22956
Everyone uses "Properties" window during design mode. When we switch to code view, we dont need properties window.
Is it possible to auto hide properties window while entering code view from design view?
Upvotes: 9
Views: 3348
Reputation: 2842
for vs2015, vs2017, vs2019 :
edit3: code works on c# winforms , WPF , xamarin.android projects,
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;
}
bool enabled = true;
private void OnWindowActivated(Window gotFocus, Window lostFocus) {
if(!enabled)
return;
//project_details();
HidePropertiesWindowInCodeOrTextView(gotFocus);
}
public void HidePropertiesWindowInCodeOrTextView(Window gotFocus) {
//System.Windows.MessageBox.Show( gotFocus.Document.Name +"" );
if (gotFocus.Document == null)
return;
var propWin = DTE.Windows.Item(Constants.vsWindowKindProperties);
var curTabTitle = gotFocus.Caption;
if (isAndroidProject())
{
propWin.AutoHides = !curTabTitle.EndsWith(".axml");
}
else if( isWpfProject(gotFocus) )
{
propWin.AutoHides = !curTabTitle.EndsWith(".xaml");
}
else //winforms
{
propWin.AutoHides = !curTabTitle.EndsWith(" [Design]");
}
//pwin.AutoHides = true; // pwin.Activate();
}
//TODO:: make it like android proj detector in future
public bool isWpfProject(Window gotFocus) {
if (DTE == null || DTE.ActiveWindow == null)
return false;
bool isWpfProj = gotFocus.Caption.EndsWith(".xaml") || gotFocus.Caption.EndsWith(".xaml.cs");
return isWpfProj;
}
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 + "");
}
}
}
Upvotes: 2