I'm adding items to a RibbonDropDown
that is used by the New Email inspector at run time. I add the items on start-up and also refresh the list on demand (when the user presses a button)
public void RefreshListNames()
{
Logger.Log("Refresh Mail Lists");
Globals.Ribbons.Ribbon1.rddListNames.Items.Clear();
foreach (KeyValuePair<Guid, string> kvp in _dda.GetMarketingListNames())
{
Microsoft.Office.Tools.Ribbon.RibbonDropDownItem dd =
Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
dd.Tag = kvp.Key;
dd.Label = kvp.Value;
Logger.Log("Adding " + dd.Label);
Globals.Ribbons.Ribbon1.rddListNames.Items.Add(dd);
}
Globals.Ribbons.Ribbon1.rddListNames.ResumeLayout();
}
Note: rddListNames
is a RibbonDropDown
This method is called in the ThisAddIn_Startup
method and populated corectly on start-up. However, any new Mail window ends up with a blank dropdown - no items. Even refreshing the list doesn't add the items back again.
I added some logging: it shows that the method is running when the 'refresh button' is pressed:
23/04/2013 14:36:43 - Refresh Mail Lists
23/04/2013 14:36:45 - Adding Marketing List - Dynamic
23/04/2013 14:36:45 - Adding Marketing List - Bs
23/04/2013 14:36:45 - Adding Marketing List - As
Why does the drop down keep loosing items? And why don't they come back, even if I explicitly refresh them?
If you make control modifications to the Ribbon UI, you need to invalidate the control cache via IRibbonControl.Invalidate()
or IRibbonControl.InvalidateControl
. This will trigger a repaint of the Ribbon elements.
Globals.Ribbons.Ribbon1.Invalidate();
// or...
Globals.Ribbons.Ribbon1.InvalidateControl("ddMarketingList");