Perhaps Jeremy if you see this you can explain if I have done the following correctly, because the method seems like a convoluted way to do what I was hoping to be simply have commands invoked off a ribbon to act according to the current "radio button" states. I looked to your "Roll Your Own Toggle Button" hoping to find out how to read the current ribbon button state. I did not see that mentioned. The convoluted way to read the state is devised like the roll your own toggle method. The ribbon application radio button invokes an external command that turns around to set a public string in the ribbon application that other external commands can read when they are invoked. It works but I am wondering if this what we are supposed to be doing. The technique, if correct, shows how ribbon commands can read the state of other ribbon items as long as a state change on those items can invoke a command. I have not found any explanation on how to do this anywhere.
For example here are parts of what is the ribbon making IExternalApplication :
static string _path = typeof(Application).Assembly.Location; /// Singleton external application class instance. internal static AppFPRibbon _app = null; /// Provide access to singleton class instance. public static AppFPRibbon Instance { get { return _app; } } /// Provide access to the radio button state static string _pb_state = String.Empty; public static string PB_STATE { get { return _pb_state; } } public Result OnStartup(UIControlledApplication a) { _app = this; Add_WTA_FP_Ribbon(a); return Result.Succeeded; }
Here the radio buttons invoke commands that function only to set the PB_STATE:
ToggleButtonData tbSTD = new ToggleButtonData("tbSTD", " STD" , ExecutingAssemblyPath, ExecutingAssemblyName + ".CmdSetAs_STD"); ToggleButtonData tbEC = new ToggleButtonData("tbEC", " EC", ExecutingAssemblyPath, ExecutingAssemblyName + ".CmdSetAs_EC");
Those "CmdSetAs_" commands turn around to call the following back in the ribbon making class:
public void SetAs_STD() { _pb_state = "STD"; System.Windows.MessageBox.Show(_pb_state,"_pb_state was set to"); } public void SetAs_EC() { _pb_state = "EC"; System.Windows.MessageBox.Show(_pb_state, "_pb_state was set to"); }
This is one of the "CmdSetAs_" commands the radio button executes:
[Transaction(TransactionMode.Manual)] class CmdSetAs_STD : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { AppFPRibbon.Instance.SetAs_STD(); System.Windows.MessageBox.Show(AppFPRibbon.PB_STATE, "_pb_state reads as"); return Result.Succeeded; } }
The MessageBox line show the PB_STATE would be readable by other ribbon commands.
Thank you for your articles.