AnsweredAssumed Answered

Custom button OnUpdate logic does not get executed when using DelegateCommands Model

Question asked by shohei_kusanoesrij-esridist Employee on Dec 15, 2015
Latest reply on Dec 15, 2015 by shohei_kusanoesrij-esridist

I’m trying to test implementation of custom button which uses DelegateCommands Model as described in the following wiki page:

 

ProGuide Buttons: Use a static module method as a button class definition

 

I am able to execute the referenced static method on my module, but cannot execute the OnUpdate logic support via the naming convention.

 

In my Daml:

<modules>
  <insertModule id="MyAddIn_Module" className="MainModule" autoLoad="false" caption="Module1">
    <tabs>
      <tab id="MyTab" caption="My Tab">
        <group refID="MyGroup" />
      </tab>
    </tabs>
    <groups>
      <group id="MyGroup" caption="My Group" appearsOnAddInTab="true">
        <button refID="MyCustomButton" size="large" />
      </group>
    </groups>
    <controls>
      <button id="MyCustomButton" caption="My Custom Button" className="MyAddIn_Module:OnMyCustomButtonClick" loadOnClick="true" condition="esri_mapping_onlyFeatureLayersSelectedCondition" smallImage="Images\GenericButtonBlue16.png" largeImage="Images\GenericButtonBlue32.png">
        <tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
      </button>
    </controls>
  </insertModule>
</modules>

 

In my MainModule.cs:

namespace MyAddIn
{
    internal class MainModule : Module
    {
        private static MainModule _this = null;


        ....


        internal static async Task OnMyCustomButtonClick()
        {
            await QueuedTask.Run(() =>
            {
                System.Diagnostics.Debug.WriteLine("OnClick called");
            });
        }


        internal static async Task CanOnMyCustomButtonClick()
        {
            await QueuedTask.Run(() =>
            {
                System.Diagnostics.Debug.WriteLine("OnUpdate called");
            });
        }


    }
}

 

In the code above, CanOnMyCustomButtonClick method does not get executed. I’m assuming that OnUpdate logic support via the naming convention is equivalent of overriding OnUpdate() of Button base class. Do I need an additional step to make the CanOnMyCustomButtonClick method to be get executed?

 

Note: If I explicitly create MyCustomButton and referece it from DAML (className="MyCustomButton"), the OnUpdate method is executed automatically.

internal class MyCustomButton : Button
{
    protected override void OnClick()
    {
        System.Diagnostics.Debug.WriteLine("OnClick called");
    }


    protected override void OnUpdate()
    {
        base.OnUpdate();


        System.Diagnostics.Debug.WriteLine("OnUpdate called");
    }
}

Outcomes