Select to view content in your preferred language

Enable/Disable Buttons with Condition based on state

2296
2
Jump to solution
06-30-2021 10:38 AM
TimothyReed1
Emerging Contributor

Hello all.  I have a plugin where I have a Connect and Disconnect  button.  I've been exploring the use of conditions to enable/disable the buttons.  What I cannot figure out is how to have the Connect enabled while the Disconnect is disabled from the start.  Below is the snippet from my Config.daml.  With this setup the Connect and Disconnect buttons are disabled from the start.  Based on the state of the connection I'd like the button state to change too.

 

Thanks!

 

        <button id="btnConnect" caption="Connect" className="Connect" smallImage="Images\greenCheck16.png" largeImage="Images\greenCheck32.png" condition="Disconnected">
          <tooltip heading="Tooltip">
 Use this button to connect to the system
 </tooltip>"
 </button>
        <button id="btnDisconnect" caption="Disconnect" className="Disconnect" smallImage="Images\redX16.png" largeImage="Images\redX32.png" condition="Connected">
          <tooltip heading="Tooltip">
 Use this button to disconnect to the system
 </tooltip>"
 </button>
      </controls>
    </insertModule>
  </modules>
<conditions>
<!-- our custom condition -->
<insertCondition id="Connected" caption="Connected to the system">
<!-- our condition is set true or false based on this underlying state -->
<state id="connected" />
</insertCondition>
<insertCondition id="Disconnected" caption="Disconnected from the system">
<!-- our condition is set true or false based on this underlying state -->
<state id="disconnected" />
</insertCondition>
</conditions>
0 Kudos
1 Solution

Accepted Solutions
KrisCulin
Frequent Contributor

I think you're on the right track.

I would first setup your conditions like this:

<insertCondition id="Disconnected_condition">
<not>
<state id="Connected_state" />
</not>
</insertCondition>

<insertCondition id="Connected_condition">
<state id="Connected_state" />
</insertCondition>

By default, you are in a disconnected state so your connect button should be enabled.  Your disconnect button should be disabled.

In the OnClick method of your connect button, change the state:

FrameworkApplication.State.Activate("Connected_state");

The UI should automatically update itself and your connect button should become disabled and your disconnect button enabled.

In the OnClick method of your disconnect button, change the state:

FrameworkApplication.State.Deactivate("Connected_state");

At this point, your disconnect button should now disable and your connect button is enabled.

HTH,

Kris

p.s. instead of using hard-coded strings, I recommend using constants.  You won't be able to use the constants in the config.daml file but you will be able to use them in code.

View solution in original post

2 Replies
KrisCulin
Frequent Contributor

I think you're on the right track.

I would first setup your conditions like this:

<insertCondition id="Disconnected_condition">
<not>
<state id="Connected_state" />
</not>
</insertCondition>

<insertCondition id="Connected_condition">
<state id="Connected_state" />
</insertCondition>

By default, you are in a disconnected state so your connect button should be enabled.  Your disconnect button should be disabled.

In the OnClick method of your connect button, change the state:

FrameworkApplication.State.Activate("Connected_state");

The UI should automatically update itself and your connect button should become disabled and your disconnect button enabled.

In the OnClick method of your disconnect button, change the state:

FrameworkApplication.State.Deactivate("Connected_state");

At this point, your disconnect button should now disable and your connect button is enabled.

HTH,

Kris

p.s. instead of using hard-coded strings, I recommend using constants.  You won't be able to use the constants in the config.daml file but you will be able to use them in code.

Wolf
by Esri Regular Contributor
Esri Regular Contributor
0 Kudos