none
VSIX set command initial state disabled RRS feed

  • Question

  • I have a VSIX package where I use the autoloading feature

    [ProvideAutoLoad(UIContextGuids80.SolutionExists)]

    When I create my command I set the state to Disabled

    CommandID menuCommandID = new CommandID(GuidList.guidMyPackageCmdSet, (int)PkgCmdIDList.MyCommand);
                    menuItem = new MenuCommand(MenuItemCallback, menuCommandID);
                    menuItem.Enabled = false;

    But after Visual Studio starts the corresponding button in Tools menu is enabled, and isn't until I click the button and VS load the package that it gets disable.

    How can I set the initial state of the button to disabled?

    Thursday, March 26, 2015 10:21 PM

Answers

  •  

    When a package is not loaded yet, the state (enabled, visible, etc.) of its commands is controlled by command flags in the .vsct file. To set a command disabled, use:

    <Button ...>
    ...
       <CommandFlag>DefaultDisabled</CommandFlag>
    ...
    </Button>


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Friday, March 27, 2015 6:44 AM
    Moderator

All replies

  •  

    When a package is not loaded yet, the state (enabled, visible, etc.) of its commands is controlled by command flags in the .vsct file. To set a command disabled, use:

    <Button ...>
    ...
       <CommandFlag>DefaultDisabled</CommandFlag>
    ...
    </Button>


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Friday, March 27, 2015 6:44 AM
    Moderator
  • Once set <CommandFlag>DefaultDisabled</CommandFlag> How Can enabled this? As package is not loaded where to set this to enable?
    Tuesday, July 30, 2019 4:52 AM