I am trying to create an AddIn with two buttons where the state is controlled with conditions. This is working but the button state is Disabled on program startup. I need a way to have one of the buttons Enabled on startup. I can't seem to find any code to allow me to have the button Enabled on startup.
Success!! I found the following code and was able to get it to work.
protected override bool Initialize() //Called when the Module is initialized. { ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to Project opened event return base.Initialize(); } private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler { MessageBox.Show($"{Project.Current} has opened"); //show your message box //Put the button code here to activate or deactivate } protected override void Uninitialize() //unsubscribe to the project opened event { ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe return; } Thank you so much for your help..... AWESOME!!!!!!!!!!
This sounds hopeful.... I'm not sure how to accomplish what you are suggesting. There is an override in my module now:
protected override bool CanUnload() { //TODO - add your business logic //return false to ~cancel~ Application close return true; }
Can I use this one or do I need to define another override? Also, I am not sure how to subscribe to the ProjectOpenedEvent or how to use the event handler. I guess I am in a little over my head on this one.
Hi Sam,
One way you can do this -
In your Module class' Initialize override, you can subscribe to an event such as the ProjectOpenedEvent. The event handler can set your custom state. This way when a project opens, your states will get evaluated immediately.
Thanks Uma for the response. I have tried that and also set my button's loadOnClick="false" as well. I think that the problem is that I am using a custom condition.
<insertCondition id="Controls_Button_condition" caption="Button Controls"> <!-- our condition is set true or false based on this underlying state --> <state id="button_state"/> </insertCondition>
I believe that the condition is evaluated to be false or disabled button at startup. I have no way of setting "button_state" on startup. I have successfully changed the state after running the program and the button will switch between enabled and disabled as I want it to. I just need the button to be enabled on startup and currently, the button starts out disabled.
Thanks in advance for your help.
Sam
Hi Sam
By default, an add-in's module is set to be loaded just-in-time (JIT). So when Pro application loads, your logic to enable the button is not invoked yet. You can change this by modifying the "autoload" attribute in the config.daml - Set this to false.
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>modules</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>insertModule</SPAN> <SPAN class="attr-name token">id</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>acme_mainModule<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">caption</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Acme<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">className</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>MainModule<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">autoLoad</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>false<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="comment token"><!--Declare additional customizations here..--></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>insertModule</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>modules</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks
Uma
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.