I've added a popup menutool on a ribbonbar and then added a button tool in that popup menu tool. The code generated by designer is:
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool1 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("ViewFile");Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool2 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("ViewFile");ribbonGroup1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[ { popupMenuTool1 });Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("ButtonTool1");Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("ButtonTool1");popupMenuTool2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[ { buttonTool1 });buttonTool2.SharedProps.Caption = "ButtonTool1";this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[ { popupMenuTool2, buttonTool2 });
It seems that designer is creating a copy of every tool placed on Ribbon. When i deleted the button tool the designer deleted the buttonTool1 but didnt delete the buttonTool2 which was a copy. Im used to adding and deleting controls in which case there will a lot of redundant code generated resulting in performance hit.
Why is that a separate copy of every tool being added on ribbon is created and on deletion the copy is actually not deleted from the code?
Thnks,
--Ayub
For each tool you create at design time, there is a root tool and an instance tool created. All tools of the same type with the same key will have one root tool that holds all the shared properties for that tool and its instances. Each instance tool holds other properties that only apply to a specific instance of the tool on a menu, toolbar, or ribbon group. Notice how one copy of the menu tool is getting added to the ribbon group (that is the instance tool) and another copy is added to the Tools collection on the toolbars manager (that is the root tool). When you delete a tool from a ribbon group at design-time, only the instance tool is deleted. The root tool remains in the toolbars manager and that is why the 'copy' is never removed. You can remove these root tools by right-clicking on the toolbars manager and selecting 'Customize...' Then go to the 'Tools' tab and you will see a list of the root tools.
Hi Mike,
Thnks for the quick reply. I have to add tool items mostly buttons in popup menu on ribbon at runtime, I have tried the following code:
foreach(string str in filesList){
ButtonTool _buttonTool = new ButtonTool(str);_buttonTool.SharedProps.Caption = str;ultraToolbarsManager1.Tools.Add(_buttonTool);((PopupMenuTool) ultraToolbarsManager1.Tools["View File"]).Tools.Add(_buttonTool);
}
In the above code snippet im trying to add button tools on a popup menu with key "View File". Here i've made a single instance and used it in both toolbarmanager and popupmenu and it is working fine. But in the designer the same thing is achieved by making separate instances. Do you think the above code snippet is fine or kindly give suggestions in case of disagreement.
This will work ok, but when you add the tool to the menu, it is actually cloned internally. If you had set any InstanceProps on the tool instance, they would actually be lost. If you do ever need to set any InstanceProps, use this code instead:
foreach(string str in filesList){ButtonTool _buttonTool = new ButtonTool(str);_buttonTool.SharedProps.Caption = str;ultraToolbarsManager1.Tools.Add(_buttonTool);ButtonTool _buttonToolInstance = (ButtonTool) ((PopupMenuTool) ultraToolbarsManager1.Tools["View File"]).Tools.AddTool(_buttonTool.Key);
_buttonToolInstance.InstanceProps.IsFirstInGroup = true;}
If i am not setting any instance properties i.e. im only setting caption for the tools then will the code posted by me in the previous reply work fine??
Thnks
Thnks Mike.
Yes, it should work fine.