C# - Checking if ContextMenu contains an item
I have a ContextMenu with some items, at runtime I add new items to that ContextMenu and I want to know how I can check if the ContextMenu contains the item, if the same item is already in the Con开发者_Python百科textMenu then dont add the item again. Only add items that are not in the ContextMenu.
How can I do that?
this works perfectly :
ContextMenu menu = new ContextMenu();
MenuItem item = new MenuItem();
menu.MenuItems.Add(0, item);
if (menu.MenuItems.Contains(item))
Console.WriteLine("The item exists");
精彩评论