Select to view content in your preferred language

Turn button off by condition

118
2
2 weeks ago
ModyBuchbinder
Esri Regular Contributor

I would like to turn on/off some buttons on Pro start.

For example check if I am on testing env and turn on some new buttons but do not show them in production.

The state of the button is define on startup and do not changed.

So I created a condition and add the element

condition="cond1"

to the button line in daml and it works. The only problem is that the button become disable but still exists.

I would like the button to be invisible not disable.

I tried to add the same condition element to the group (I put the button in a separate group) but it does not work.

Is there any way to drop the button by condition or in any other way?

Happy new year!

0 Kudos
2 Replies
JoePolaski
Occasional Contributor

Yes this is possible, just like your condition toggles the Enabled field. You will need a second property that is a Visibility type. You can then, at the same time you check or set that boolean, set your visibility to Hidden when it is false. Then just have the Visible property of the button bound to your visibility property. I hope this is helpful. It sounds like you are most of the way there already. Best of luck!

0 Kudos
CharlesMacleod
Esri Regular Contributor

Mody, buttons cannot be hidden on the ribbon - only disabled.

However, it is possible to delete buttons from the daml via a Configuration at start up. There is a callback u can override in the ConfigurationManager class called "OnUpdateDatabase". In many of the samples (and in many demos we have done) we show deleting many of the Pro tabs - u wld apply the same logic to delete buttons.

For example: https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Configuration/ConfigWithMap/Con...

Here are the key lines:

//here is where the tab elements are selected
var tabElements = from seg in database.Root.Descendants(nsp + "tab") select seg;

//In your case u wld be selecting buttons - eg
var buttonElements = from seg in database.Root.Descendants(nsp + "button") select seg;

 

Then, in a loop, the sample examines each tab element (probably around 100 or so). It skips any of its own tabs (tab ids beginning with "ConfigWithMap" or "Acme" and any on the backstage). It adds all of the other tab elements into a collection where they will be deleted.

 

if (... tabElement.Parent.Name.LocalName.StartsWith("backstage"))
  continue;//keep backstage tabs
//delete all tabs other than "our" own
if (!id.Value.StartsWith("Acme") && !id.Value.StartsWith("ConfigWithMap"))
  elements.Add(tabElement);//any tab added here will be deleted

//u wld do similar logic to delete buttons
if (id.Value == "some_button_daml_id_which_I_want_to_delete_off_the_ribbon")
  elements.Add(btnElement);

 

The tabs are deleted in a separate loop here:

foreach (var element in elements){
  element.Remove();//delete all the tabs (or buttons in your case)
}

(fyi - attempting to delete them within the same loop as the search will throw an exception)

 

Read more about configurations here: https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Configurations 

 

0 Kudos