protected void setCommand(string itemName, RelayCommand command) { if (!menuItemDictionary.ContainsKey(itemName)) { throw new InvalidOperationException("No menu item with the name '" + itemName + "' exists in the menu."); } TECMenuItem item = menuItemDictionary[itemName]; item.Command = command; }
protected TECMenuItem addMenuItem(string newItemName, string disabledText = null, string parentItemName = null) { if (menuItemDictionary.ContainsKey(newItemName)) { throw new InvalidOperationException("A menu item with the name '" + newItemName + "' already exists."); } if (parentItemName == null) //Add base menu item { TECMenuItem newBaseItem = new TECMenuItem(newItemName, true); if (disabledText != null) { newBaseItem.DisabledText = disabledText; } menuItemDictionary.Add(newBaseItem.Name, newBaseItem); _menu.Add(newBaseItem); return(newBaseItem); } else //Add child menu item { if (!menuItemDictionary.ContainsKey(parentItemName)) { throw new InvalidOperationException("Menu item with the name '" + parentItemName + "' doesn't exist."); } TECMenuItem parentItem = menuItemDictionary[parentItemName]; TECMenuItem newChildItem = new TECMenuItem(newItemName, false); if (disabledText != null) { newChildItem.DisabledText = disabledText; } menuItemDictionary.Add(newChildItem.Name, newChildItem); parentItem.AddMenuItem(newChildItem); return(newChildItem); } }