Version

Adding and Removing Items

You can add and remove menu items in xamMenu or xamContextMenu. To add an item to the items collection, use the Add method of the menu or menu item’s Item Collection. There are two remove methods: Remove and RemoveAt which exists on the Item Collection as well.

The following code shows you how to add and remove items in xamMenu.

In Visual Basic:

' Create Edit menu item
Dim parentMenuItem As New XamMenuItem()
parentMenuItem.Header = "Edit"
menu1.Items.Add(parentMenuItem)
' Remove a submenu item
Dim item As XamMenuItem = TryCast(menu1.Items(0), XamMenuItem)
item.Items.RemoveAt(0)

In C#:

// Create a menu item
XamMenuItem parentMenuItem = new XamMenuItem();
parentMenuItem.Header = "Edit";
// Add menu item
menu1.Items.Add(parentMenuItem);
// Remove a submenu item
XamMenuItem item = menu1.Items[0] as XamMenuItem;
item.Items.RemoveAt(0);