1

When I set the onDemand="false" attribute, my buttons disappear from my menu!

I'm setting the attribute to false so that I control its behaviour using the OnUpdate override in code. Am I doing anything wrong?

<ArcMap>
<Commands>
<Button id="SayHi_Btn" onDemand="false" class="SayHiButton" caption="Say Hi!" image="Images\SayHi_Btn.png" />
<Button id="SayHello_Btn" onDemand="false" class="SayHelloButton" caption="Say Hello!" image="Images\SayHello_Btn.png" />
<Button id="SayAloha_Btn" onDemand="false" class="SayAlohaButton" caption="Say Aloha!" image="Images\SayAloha_Btn.png" />
</Commands>
<Menus>
<Menu id="ChooseGreeting_RootMenu" caption="Choose Greeting" isRootMenu="true">
<Items>
<Button refID="SayHello_Btn" separator="true" />
<Button refID="SayAloha_Btn" />
<Button refID="SayHi_Btn" />
</Items>
</Menu>
</Menus>
</ArcMap>
0

Just found that if there are any uncaught exceptions being thrown inside the OnUpdate, then the buttons disappear from the menu items.

Best to implement robust exception management inside the OnUpdate method to prevent unexpected behaviour by the buttons.

using ESRI.ArcGIS.Desktop.AddIns;

namespace ArcMapAddIn
{
    public class MyCustomButton : Button
    {
        private readonly MyExtension _myExtension;

        public MyCustomButton()
        {
            _myExtension = AddIn.FromID(ThisAddIn.IDs.MyExtension);

            Enabled = false;
        }

        protected override void OnClick()
        {
            new MessageBox.Show("My Custom Button clicked!");
        }

        protected override void OnUpdate()
        {
            Enabled = _myExtension.CanShowCustomMessage;
            // if uncaught excpetion is thrown here- this button gets removed from menu item
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.