title: Dynamic Visibility of menu item
body: <p>In my VS extension I need to add menu item for my new project type. But I want it to show for my custom type only. So I added this code to .vcst file:</p>
  
  <pre><code>  &lt;Button guid="_Interactive_WindowCmdSet" id="cmdidLoadUI" priority="0x0100" type="Button"&gt;
      &lt;Parent guid="_Interactive_WindowCmdSet" id="ProjectItemMenuGroup" /&gt;
      &lt;Icon guid="guidImages" id="bmpPic1" /&gt;
      &lt;CommandFlag&gt;DynamicVisibility&lt;/CommandFlag&gt;
      &lt;Strings&gt;
        &lt;ButtonText&gt;Load&lt;/ButtonText&gt;
      &lt;/Strings&gt;
    &lt;/Button&gt;
  
  
    &lt;Group  guid="_Interactive_WindowCmdSet" id="ProjectItemMenuGroup" priority="0x0600"&gt;
      &lt;Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE"/&gt;
    &lt;/Group&gt;
  </code></pre>
  
  <p>And added this code to package initialization:</p>
  
  <pre><code>            // Create the command for the menu item.
              CommandID projectMenuCommandID = new CommandID(GuidList.Interactive_WindowCmdSet, (int)PkgCmdIDList.cmdidLoadUI);
              OleMenuCommand projectmenuItem = new OleMenuCommand(LoadUIMenuItemCallback, projectMenuCommandID);
              projectmenuItem.BeforeQueryStatus += projectmenuItem_BeforeQueryStatus;
              mcs.AddCommand(projectmenuItem);
  </code></pre>
  
  <p>And query status handler is:</p>
  
  <pre><code>    private void projectmenuItem_BeforeQueryStatus(object sender, EventArgs e)
      {
          OleMenuCommand menuCommand = sender as OleMenuCommand;
  
          if (menuCommand != null)
              menuCommand.Visible = IsProjectOfRightType(GetSelected&lt;Project&gt;());
      }
  </code></pre>
  
  <p>The problem is - this status handler never get called. So I have this menu item showed for all project types.</p>
  
  <p>I've tried also to implement <code>IOleCommandTarget</code> interface on my package, like:</p>
  
  <pre><code>    public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
      {
          // Disable all commands in case if project is VisuaART project, otherwise - disable them.
          OLECMDF cmdf;
  
          for (int i = 0; i &lt; cCmds; i++)
          {
              var command = prgCmds[i];
              if (command.cmdID == PkgCmdIDList.cmdidLoadUI)
              {
                  if (IsProjectOfRightType(GetSelected&lt;Project&gt;()))
                      command.cmdf = (uint)COMMAND_SUPPORTED;
                  else
                      command.cmdf = (uint)COMMAND_UNSUPPORTED;
              }
  
          }
          return VSConstants.S_OK;
      }
  
      private const OLECMDF COMMAND_SUPPORTED = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED;
      private const OLECMDF COMMAND_UNSUPPORTED = OLECMDF.OLECMDF_INVISIBLE;
  </code></pre>
  
  <p>But that doesn't helped either. Method is called, but setting <code>OLECMDF.OLECMDF_INVISIBLE</code> does nothing. What should I do to hide this menu item for unsupported menu items?</p>