create toggle button in toolbar

367 Views Asked by At

I am using MS CRM and USD where I am suppose to create a toggle button using WPF hosted control. I followed the tutorial over here.However I want to change the text of button after it is clicked.

1

There are 1 best solutions below

0
On

To do literally what you describe may require more effort and complexity than a resonable alternative, so I want to explore both of those possiblities here.

The Desired Answer: Replicating Toggle Button Behavior on Non-Toggle USD Buttons

  1. Set the Button's label to a $Context parameter, like [[$Context.ToggleButtonText]]. Be sure to push this value at DesktopReady using your Global Manager's CopyToContext action. We'll use this label to define the state of the button, so let's say that we'll only push values "On" and "Off" to this parameter.
  2. Similarly, set a $Context parameter to indicate whether the button is changing, like [[$Context.ToggleButtonIsChanging]]. Upon DesktopReady, set this to false. The same Action Call can push both ToggleButtonText and ToggleButtonIsChanging to $Context simultaneously.
  3. Define three Action Calls for the button click. 3a. The first Action Call will set ToggleButtonIsChanging to true. 3b. The next two Action Calls should be given names like "Toggle Button to Off" and "Toggle Button to On". Both Action Calls should do nothing but perform a condition check, thereby authorizing or preventing their Sub-Actions from firing. (More on defining these Sub-Actions to come.) I recommend using the Global Manager's Pause action to perform a 1ms Pause when the condition is true. 3c. For Toggle Button to Off, the Condition should be "[[$Context.ToggleButtonText]]"=="On"&&[[$Context.ToggleButtonIsChanging]]. For Toggle Button to On, the Condition should be "[[$Context.ToggleButtonText]]"=="Off"&&[[$Context.ToggleButtonIsChanging]].
  4. Define Sub-Actions for "Toggle Button to Off" and "Toggle Button to On." 4a. The first Action Call (and if necessary, any of its Sub-Actions) should perform the desired automation(s) that would correspond to the Button's state change. In other words, what the button actually does goes here. 4b. The second Action Call should finalize the button's state change by pushing new $Context parameters. Under "Toggle Button to Off," you want this action to set ToggleButtonText to Off and ToggleButtonIsChanging to false. Under "Toggle Button to On," you want this action to set ToggleButtonText to On and ToggleButtonIsChanging to false.

A Simpler Suggestion: Separate Buttons with Visibility Conditions

  1. Define two buttons, "On" and "Off."
  2. Upon DesktopReady, push a value "On" or "Off" to [[$Context.ButtonState]].
  3. Define Visibility Conditions for both buttons. For example, the On button should only be visible if "[[$Context.ButtonState]]"=="On"
  4. Define Automations for both buttons. You'll need at least two Action Calls. 4a. For each button, your first Action Call(s) should define the desired automation(s). 4b. The very last Action Call under each button should push the converse value to $Context. For example, the On button's final action should CopyToContext ButtonState=Off.