The following code shows what I' am try todo: I want to initialize a popup menu with a couple of menu item programmatically. Some of them should be regrouped and the group should be separated by horizontal separator lines:
ultraToolbarsManager > ultraToolbar > popup >
menu item1
menu item2
--------------------------------
buttonToolGenerateHA
menu item3
menu item4
ultraToolbarsManager "ultraToolbarsManagerDP" contains a ultraToolbar "ultraToolbarDP" to which a popup menu "popupFunctions" containing the menu (buttontool) item "buttonToolGenerateHA" should be appended
before the menu item a separator line should be placed, why I set the IsFirstInGroup property to true.
I tried different combination, actually I can't set the property, either buttonToolGenerateHA.InstanceProps is null or setting the IsFirstInGroup property is ignored. The menu item are displayed without separator
Any idea to init the tools correctly programmatically?
----------------------------------
//>>> buttonToolGenerateHA.InstanceProps != null
ultraToolbarDP.NonInheritedTools.AddRange(new ToolBase[] { popupFunctions,});
ultraToolbarsManagerDP.Toolbars.AddRange(new UltraToolbar[] { ultraToolbarDP, });
//>>> attach Tools to the Toolbar manager
ultraToolbarsManagerDP.Tools.Add(buttonToolGenerateHA);
//>>> buttonToolGenerateHA.InstanceProps = null!
popupFunctions.Tools.Add(buttonToolGenerateHA);
??? when to set buttonToolGenerateHA.InstanceProps.IsFirstInGroup = true; ???
Hello,
Before I explain what is happening and how to resolve your issue, I suggest reviewing the "Root Tools and Instance Tools" section provided in our online help to familiarize yourself with these items.
When you add a tool (buttonToolGenerateHA) to the PopupMenuTool's Tools collection, you are adding the root tool. When it is added, it is cloned and an instance tool is inserted into the collection. As 'buttonToolGenerateHA' is still referring to the root tool, it does not have a InstanceProps available. To access the InstanceProps, you'll need to index (by index or key) into the Tools collection of the PopupMenuTool.
popupFunctions.Tools[buttonToolsGeneratedHA.Key].InstanceProps.IsFirstInGroup = true;
I hope this helps. Let me know if you need further assistance.
Thanks,
Chris
Sorry to dredge up such an old topic but I'm running into the issue and I tried the VERIFIED ANSWER
...ToolbarsManager.Tools["Publish Template"].InstanceProps.IsFirstInGroup = true;
and InstanceProps there is also NULL.
InstanceProps is null in this case because the tool you are accessing is a root tool. InstanceProps is only non-null on a tool that is on a toolbar or a menu or some other displayed instance. The InstanceProps apply to a tool that is in place on some kind of container.
So, if you have a tool on a toolbar, you would could do something like this:
ToolbarsManager.Toolbars["My Tooblar"].Tools["Publish Template"].InstanceProps.IsFirstInGroup = true;
But you have to get a tool on a toolbar, you can't use the root tool, because the root tool is essentially a template for that tool so that an instance of that tool can be created and placed somewhere.