Hi all,
I'd like to use a button to start a "session" in which stuff happens until I click the button again (like an edit session only different behavior).
As best I can tell, when I click the button, it speeds through the behaviour and immediately exits. That is, it views it as a one-time thing instead of as a switch.
How can I change this to more of a turn-on, turn-off thing?
Edit to give a (not the actual thing) example: a counter between button clicks. Count until I click the button again.
Hi Alfred,
To implement a switch/toggle like this, your code needs to manage the "state" of the switch (on or off).
Regardless of which way you go, essentially:
At any point you can check `stateMyButtonEnabled` to know for example if the button is currently enabled or not.
If you go with Pro "conditions", the syntax for getting/setting state is a bit different, but conceptually similar.
```
// from Gemini with prompt "arcgis pro .net toggle button state"
protected override void OnClick()
{
// Check if the state is currently active
if (ArcGIS.Desktop.Framework.State.Contains("stateMyButtonEnabled "))
{
// If active, deactivate it
ArcGIS.Desktop.Framework.State.Deactivate("stateMyButtonEnabled ");
}
else
{
// If inactive, activate it
ArcGIS.Desktop.Framework.State.Activate("stateMyButtonEnabled ");
}
}
```
Good Luck