Logo
PRB: Button of package command cannot be initially invisible on Visual Studio toolbar.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: July 2014   Microsoft Visual Studio 2012
      Microsoft Visual Studio 2013
Introduction

When you use the folliwing flags to make a button initially invisible on a toolbar, the button is visible but disabled:

<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>

The button is invisible as expected if placed on a menu or on a toolbar of a toolwindow, but not on a regular toolbar.

More Information

The following .vsct file of a package shows the problem. It creates two buttons (one of them visible, the other invisible) on three locations: the "Tools" menu, the "Standard" toolbar and the toolbar of the Solution Explorer. While the invisible button is shown neither on the "Tools" menu nor on the toolbar of the Solution Explorer, it is shown (disabled) on the "Standard" toolbar.

Language: XML   Copy Code Copy Code (IE only)
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

   <Extern href="stdidcmd.h"/>
   <Extern href="vsshlids.h"/>

   <Commands package="guidVSPackageInvisibleButtonPkg">

      <Buttons>

         <Button guid="guidVSPackageInvisibleButtonCmdSet" id="cmdidMyInvisibleCommand" priority="0x0100" type="Button">
            <Parent guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup"/>
            <Icon guid="guidImages" id="bmpPic1" />
            <CommandFlag>DynamicVisibility</CommandFlag>
            <CommandFlag>DefaultInvisible</CommandFlag>
            <Strings>
               <CommandName>cmdidMyInvisibleCommand</CommandName>
               <ButtonText>My Invisible Command</ButtonText>
            </Strings>
         </Button>

         <Button guid="guidVSPackageInvisibleButtonCmdSet" id="cmdidMyVisibleCommand" priority="0x0101" type="Button">
            <Parent guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup"/>
            <Icon guid="guidImages" id="bmpPic2" />
            <Strings>
               <CommandName>cmdidMyVisibleCommand</CommandName>
               <ButtonText>My Visible Command</ButtonText>
            </Strings>
         </Button>

      </Buttons>

      <Bitmaps>
         <Bitmap guid="guidImages" href="Resources\Images_32bit.bmp" usedList="bmpPic1, bmpPic2"/>
      </Bitmaps>

      <Groups>
         <Group guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup" />
      </Groups>
      
   </Commands>

   <CommandPlacements>
   
      <CommandPlacement guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup" priority="0x600">
         <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </CommandPlacement>
      <CommandPlacement guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup" priority="0x600">
         <Parent guid="guidSHLMainMenu" id="IDM_VS_TOOL_STANDARD"/>
      </CommandPlacement>
      <CommandPlacement guid="guidVSPackageInvisibleButtonCmdSet" id="MyGroup" priority="0x600">
         <Parent guid="guidSHLMainMenu" id="IDM_VS_TOOL_PROJWIN"/>
      </CommandPlacement>

   </CommandPlacements>
   
   <Symbols>

      <GuidSymbol name="guidVSPackageInvisibleButtonPkg" value="{dfe1f246-7e67-4561-9926-9c65354461e0}" />

      <GuidSymbol name="guidVSPackageInvisibleButtonCmdSet" value="{6dd84c53-a8c8-442f-ad56-1c5b620efc12}">
         <IDSymbol name="cmdidMyInvisibleCommand" value="0x0100" />
         <IDSymbol name="cmdidMyVisibleCommand" value="0x0101" />
         <IDSymbol name="MyGroup" value="0x0200" />
      </GuidSymbol>

      <GuidSymbol name="guidImages" value="{0dd26fdc-3134-4a8e-ad61-7884a650a474}" >
         <IDSymbol name="bmpPic1" value="1" />
         <IDSymbol name="bmpPic2" value="2" />
      </GuidSymbol>
   
   </Symbols>

</CommandTable>


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)