开发者

C# - Checking if ContextMenu contains an item

开发者 https://www.devze.com 2023-03-09 11:35 出处:网络
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开发

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

精彩评论

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