locked
Changing Text of Command Dynamically (Visual Studio Extention) RRS feed

  • Question

  • Hi, so I am having trouble with 1 aspect of changing the text of a command dynamically.

    first this is the code im using

    protected override void Initialize() { base.Initialize(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if(null != mcs) { CommandID command = new CommandID(GuidList.guidTopLevelMenuCmdSet, (int)pkgCmdIDList.cmdidCommand); OleMenuCommand CommandMenu = new OleMenuCommand(new EventHandler(CommandExe), command); CommandMenu.BeforeQueryStatus += new EventHandler(OnBeforeQueryStatus);

    //OnBeforeQueryStatus changes the text of button mcs.AddCommand(command); } }

    With this code it works fine AFTER i execute the command once; however before i call the command the eventhandler does not get called.
    Friday, August 10, 2012 8:20 PM

Answers

  • VS does not load your package to run QueryStatus, it loads it to handle Exec which is why it works after you execute your command once, because it causes your package to load. Generally you need to auto-load or have your default command text be useful without any code running.

    Ryan

    Friday, August 10, 2012 8:46 PM

All replies

  • VS does not load your package to run QueryStatus, it loads it to handle Exec which is why it works after you execute your command once, because it causes your package to load. Generally you need to auto-load or have your default command text be useful without any code running.

    Ryan

    Friday, August 10, 2012 8:46 PM
  • Thanks, found answer after quick search of how to auto-load.

    Answer

    Monday, August 13, 2012 5:12 PM