Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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