Hi,
I have two questions about ribbon.
1. In my app, I created ribbon tabs, groups. Later some ButtonTool controls were added to the groups dynamically. I used RibbonGroup.Items.Insert() to add buttons, do I need to register buttons additionally? They show fine on ribbon, but the reason I am asking is that I noticed I got null when calling ribbon.GetToolById() by giving some button IDs, some return fine. However, if I programmatically loop through ribbon components, I got all buttons, as I can see from the UI, I don't know why some are not registered by ribbon.
2. Put question 1 aside, I need to remove some buttons and add them back. When I remove, I use RibbonGroup.Items.Remove(), they do get disappeared from UI, and when I programmatically loop over ribbon components, they are gone, that's right. However, if later I add some buttons back, I got error like "Tool with Id 'UserQueryRunDropDown' already exists. Cannot add multiple tool instances with the same Id." So I run GetToolById on ribbon before I add button, I do see they are still registered with ribbon, that's wrong, how do I unregister the buttons besides removing them from item collection?
Thanks for your help,
Yu
If you can provide a sample that demonstrates these issues, we can submit an issue for this and look into what is causing the problem.
Hi I second on the second question.
I populate the ribbon.ApplicationMenu.RecentItems using .Add()
The next time the user opens the recen titems list I Clear() the RecentItems list.
But if I "re-add" a button tool with an ID that was previously used I get the error that the button tool cant be added twice.
for (int i = 0; i < theRibbon.ApplicationMenu.RecentItems.Count; i++)
{
ButtonTool bt = theRibbon.ApplicationMenu.RecentItems[i] as ButtonTool;
bt.Click -= new RoutedEventHandler(btnRecent_Click);
bt = null;
theRibbon.ApplicationMenu.RecentItems[i] = null;
}
theRibbon.ApplicationMenu.RecentItems.Clear();
FileInfo[] files;
if (GetStoredRoutes(out files))
foreach (FileInfo file in files)
ButtonTool btnRecent = new ButtonTool();
btnRecent.Caption = file.Name;
btnRecent.Id = file.FullName;
btnRecent.Click += new RoutedEventHandler(btnRecent_Click);
theRibbon.ApplicationMenu.RecentItems.Add(btnRecent as object);
The only workarounds I can think of is to not set the Id on the tool or to only remove the items that you know need to be removed (i.e. items that you will not be readding). This will be addressed in the next hotfix.
This problem is preventing us from using the recent items menu, is there a workaround until we get a fix?
I was able to reproduce the exception and have submitted the issue. I'll see about getting a case created for you so you can be notified when the issue is addressed.