I have further requirement from my last implementation using this -
How to remove auto generated context menu items for the selected shape conditionally?Now I need to add some extra menu items to the context menu. I have added these command with sub menu but when i click these menu item then it does not fire the CommandContextExecuted event as like Delete and other commands. Below is the code snippet to create extra menu items in the context menu..
internal class CustomContextMenuBuilder : NDiagramContextMenuBuilder
{
public override NContextMenu BuildContextMenu(object obj)
{
NContextMenu contextMenu = null;
if (obj as NDrawingDocument == null)
{
contextMenu = new NContextMenu();
/* Added Delete option in the context menu */
contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.Delete, false));
bool isConnectorMenu = obj as NRoutableConnector != null;
if (isConnectorMenu)
contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.Reroute, true)); /* Added Reroute option in the context menu if connectors*/
/* Added SubmenuOrder in the context menu */
contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.SubmenuOrder, !isConnectorMenu));
/* Added SubmenuRotateOrFlip in the context menu */
contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.SubmenuRotateOrFlip, false));
if (offpageSystems.Count > 0) //Lets suppose it is list of String and I am creating a Sub menu
{
NCommand offpageCommand = new NCommand();
offpageCommand.Context = new NCommandContext(new NCommandProperties()
{
BeginGroup = true,
ShowArrowStyle = ShowArrowStyle.Default,
Name = "OffpageParent",
ID = ((int)DiagramCommand.LastCommandId + 20),
Text = "Offpage HVAC Systems"
});
contextMenu.Commands.Add(offpageCommand);
for (int cnt = 0; cnt < offpageSystems.Count; cnt++)
{
NCommand subCmd = new NCommand(new NCommandProperties()
{
Name = string.Format("OffpageChild{0}", cnt),
ID = ((int)DiagramCommand.LastCommandId + 20 + cnt),
Text = offpageSystems[cnt].SimModelName,
Tag = offpageSystems[cnt].RowReference
});
offpageCommand.Commands.Add(subCmd);
}
}
//DiagramCommandRange
}
return contextMenu;
}
Please suggest me the correct way to create context menu items which should work as like 'Action' DiagramCommandRange. How can i create another command range so that these submenu work like them??
Thanks in Advance