Is there a way to get a reference to control on a custom Ribbon?

154
2
05-07-2020 07:52 AM
GustavoCruz
New Contributor II

Hi,

On our AddIn we have an EditBox on our custom Ribbon. I would like to access its Text from a DockPane.

I was expecting something similar to what's in place for DockPanes (FrameworkApplication.DockPaneManager.Find("the id of the dockpane")) to exist but can't find anything on the API to get a reference to a control on the Ribbon.

Thanks

Reply
0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

In theory you can use this snippet:

// Test_EditBox is the Id of the editBox in config.daml:
var plugin = FrameworkApplication.GetPlugInWrapper ("Test_EditBox");

however, currently there is a limitation in the API that doesn't allow you to access the returned plugin wrapper which is of the type: ArcGIS.Desktop.Framework.Wrappers.EditBoxWrapper, not accessible via the API.

So the best way to access the text from anywhere is to create a static string property in the Module class and set that property with the text each time the text is changed:

Module1.cs add:

internal static string EditText { get; set; }

To your EditBox class you add these overrides depending on your input trigger preference:

/// <summary>
/// Called when the 'Enter' key is pressed inside this control or when the control loses keyboard focus.
/// </summary>
protected override void OnEnter()
{
// Passes the current Text in the EditBox to the global parameter in Module1.
Module1.EditText = Text;
}

protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
// Passes the current Text in the EditBox to the global parameter in Module1.
Module1.EditText = Text;
}

If you prefer events you can also implement an OnEditBoxChanged event in you EditBox class.

GustavoCruz
New Contributor II

Thanks, I actually want to update the edit box's text on the ribbon not just read its value but I think I can manage that with events as you suggest.

Reply
0 Kudos