0

Here's my button:

  <Button guid="guidTranslationAutomatorCommandPackageCmdSet" id="ToggleCommand" priority="0x0000" type="Button">
    <Parent guid="guidTranslationAutomatorCommandPackageCmdSet" id="SubMenuGroup" />
    <CommandFlag>TextChanges</CommandFlag>
    <CommandFlag></CommandFlag>
    <Strings>
      <CommandName>cmdidTestSubCommand</CommandName>
      <ButtonText>Auto (On)</ButtonText>
    </Strings> 
  </Button>

I can toggle it's checked state once it is clicked with this:

    private void MenuItemCallback(object sender, EventArgs en)
    {
        var command = sender as OleMenuCommand;
        var mcs = this.ServiceProvider.GetService(typeof(IMenuCommandService))
            as OleMenuCommandService;
        var newCmdID = new CommandID(new Guid(TranslationAutomatorCommand.guidTranslationAutomatorCommandPackageCmdSet), command.CommandID.ID);
        MenuCommand mc = mcs.FindCommand(newCmdID);
        if (mc != null)
        {
            mc.Checked = true;
        }
    }

But I want the initial state to be checked. How do I do that? It's probably something in the .vsct file but I can't find it.

1 Answers1

0

In you package Initialize function check it.

protected override void Initialize()
    {
        var command = sender as OleMenuCommand;
        var mcs = this.ServiceProvider.GetService(typeof(IMenuCommandService))
        as OleMenuCommandService;
        var newCmdID = new CommandID(new Guid(TranslationAutomatorCommand.guidTranslationAutomatorCommandPackageCmdSet), command.CommandID.ID);
        MenuCommand mc = mcs.FindCommand(newCmdID);
        if (mc != null)
        {
            mc.Checked = true;
        }
}
Paul Swetz
  • 2,234
  • 1
  • 11
  • 28