开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜