Version

Access a Tool by Its ID

The Id property of a Ribbon tool allows you to associate a tool with a unique key. Once you associate a Ribbon tool with a unique key, you can use the key to retrieve a reference to the tool at run time. However, the Id property does not create a class level variable of the tool; you must use xamRibbon’s GetToolById method if you want to retrieve a reference to a specific tool.

In order to access a tool by its Id property, you must have a reference to an instance of a xamRibbon™ control. The simplest way to achieve this is to set the Name property of xamRibbon so that you can access the control directly from the code-behind. Once you have a reference to xamRibbon, use the GetToolById method, and pass in a Ribbon tool’s ID as the parameter.

The following example code demonstrates how to access a tool by its Id property at run time. The example code assumes that you set the Name property of xamRibbon to 'xamRibbon1' and the Id property of a ButtonTool within a RibbonGroup to 'ButtonTool1'.

In Visual Basic:

Imports Infragistics.Windows.Ribbon
...
Dim bt As ButtonTool = TryCast(Me.xamRibbon1.GetToolById("ButtonTool1"), ButtonTool)
If bt IsNot Nothing Then
        bt.Caption = "I found my ButtonTool"
End If
...

In C#:

using Infragistics.Windows.Ribbon;
...
ButtonTool bt = this.xamRibbon1.GetToolById("ButtonTool1") as ButtonTool;
if(bt != null)
{
        bt.Caption = "I found my ButtonTool";
}
...