Setting ribbon controls property in loop

Oct 13, 2014 at 9:21 PM
Hi,

I want to add dynamically loaded localization to my app that using Ribbon but , I have a problem with setting Text & ToolTip (I consider also using ToolTipTitle) property. I know I can write for each element:
ribbonButton1.Text = Resources.Strings.FormMain_ribbonButton1_Text; 
[and so on...]
This is for simple example, normally I use ResourceManager with CultureInfo
This works but, this way I have to remember to add for every newly added control (button, dropDown, etc...) two (or three) lines of code...
So with help of google I came with good looking solution:
Iterating through [control].Controls recursively but there is a catch, controls on ribbon are not placed as classic controls, so ribbon controls can no be easily enumerated in one simple loop (foreach for e.g. with recursion), so I thought I will foreach throughout declared instances... And, in result I have list of instances, now how to apply Text & ToolTip to each found ribbon control?
I have came with this so far (but this is not working):
// ribbon derived controls
FieldInfo[] list = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
foreach (FieldInfo fi in list)
{
    if (fi.FieldType.FullName.Contains("System.Windows.Forms.Ribbon"))
    {
        try
        {
            string tooltipVal = string.Empty;
            string textVal = string.Empty;
            // this routine works nice, I get strings in textVal & tooltipVal for control name
            getLocalizedRibbonControlStrings(fi.Name, out textVal, out tooltipVal);

            // Check for Text property
            PropertyInfo pi2 = fi.GetType().GetProperty("Text");
            if (pi2 != null && !string.IsNullOrEmpty(textVal))
            {
                pi2.SetValue(fi, Convert.ChangeType(textVal, pi2.PropertyType), null);
            }

            // check if there is a ToolTip prop.
            PropertyInfo pi = fi.GetType().GetProperty("ToolTip");
            if (pi != null && !string.IsNullOrEmpty(tooltipVal))
            {
                pi.SetValue(fi, Convert.ChangeType(tooltipVal, pi.PropertyType), null);
            }

        }
        catch { }
    }
}
The variable pi & pi2 is always null (but in Form designer in properties window there is property Text and ToolTip so wtf? ) .
Anyone know how to iterate through all controls on Ribbon and check_if_exists&set property?