Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
730
Redundant code generated while adding Tools on toolBarManager
posted

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

  • 44743
    posted

    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.