In which cases can I get the error:
ToolsCollectionBase owning PopupMenu root tool is invalid or null.
when removing a tool from it's own ParentCollection with following code:
var parentCollection = this.Tool.ParentCollection; if (parentCollection != null) { parentCollection.Remove(this.Tool); }
Creating the tool is done fairly simple:
var popupMenuTool = new PopupMenuTool(dropNode.ItemKey); popupMenuTool.SharedProps.Caption = dropNode.Text;
I am using a rather undocumented method to insert the Tool in the PopupMenuTool as I am creating a custom RibbonCustomizationDialog. Maybe there's a problem there... ( --> InsertToolForRibbonCustomization).
The full version of the code is:
// Remove the Tool from the ToolbarsManager and the dropNode from the UltraTree so we // can insert a PopupMenuTool instead. var dropNodeIndex = parentRibbonGroupNode.Group.Tools.IndexOf(dropNode); parentRibbonGroupNode.Group.Tools.Remove(dropToolNode.Tool); dropNode.Remove(); // Create PopupMenuTool from DropNode var popupMenuTool = new PopupMenuTool(dropNode.ItemKey); popupMenuTool.SharedProps.Caption = dropNode.Text; // Insert PopupMenuTool in the RibbonGroup at index 0 parentRibbonGroupNode.Group.Tools.InsertToolForRibbonCustomization( dropNodeIndex, popupMenuTool, isCopy, excludedToolKeys); // Create UltraTreeNode from PopupMenuTool var popupMenuNode = this.CreateNodeForTool(popupMenuTool, true, null, true); if (popupMenuTool.GetIsHiddenByMdiMerge()) { ((ToolNode)popupMenuNode).ForceVisible = isCopy; popupMenuNode.Visible = true; this.refreshMerge = true; } // Insert the popupMenuNode in the UltraTree parentRibbonGroupNode.Nodes.Insert(0, popupMenuNode); // Now that the dropNode Tool has been converted to a PopupMenuTool, add the dragNode // to the PopupMenuTool Node. First insert the Tool, then insert the UltraTreeNode. // Insert the Tool tool = popupMenuTool.Tools.InsertToolForRibbonCustomization( 0, (dragNode as ToolNode).Tool, isCopy, excludedToolKeys); // Create an UltraTreeNode from the Tool. newUltraTreeNode = this.CreateNodeForTool(tool, true, null, true); if (tool.GetIsHiddenByMdiMerge()) { ((ToolNode)newUltraTreeNode).ForceVisible = isCopy; newUltraTreeNode.Visible = true; this.refreshMerge = true; } // Insert the UltraTreeNode popupMenuNode.Nodes.Insert(0, newUltraTreeNode);
What I'm actuall trying to do is that when a ButtonTool(A) is dragged over the middle of another ButtonTool(B), then B gets transformed into a PopupMenuTool and the ButtonTool A gets added to that PopupMenuTool. The ButtonTool B is removed.
Thx, Lieven Cardoen
Hello Lieven,
Thank you for contacting Infragistics.
Would you be able to create a sample project that demonstrates this issue?
Here's a small example.
Kind regards, Lieven Cardoen
I have the impression that the PopupMenuTool isn't working all to well when created like this. Childs added to the PopupMenuTool with InsertToolForRibbonCustomization seem to loose their image...
Thank you for your response.
The method you're using is only intended to be used by the RibbonCustomizationProvider. However, if you add your tools to the UltraToolbarsManager.Tools collection before adding them to the group or PopupMenuTool you'll see the issue go away. Every tool needs to be added to the UltraToolBarsManager.Tools collection before it can be used anywhere else.
Ok, will try that and verify the answer if I manage to fix it.