Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can I set IsEnable property of menuitem when opeing contextmenu.
code below:

 m_ProjectMenu = new ContextMenu();
MenuItem MenuItem_Submit = new MenuItem();
MenuItem_Submit.Header = "Submit";

MenuItem MenuItem_Delete = new MenuItem();
MenuItem_Delete.Header = "Delete";

m_ProjectViewGrid.ContextMenu = m_ProjectMenu;
m_ProjectViewGrid.ContextMenuOpening += new ContextMenuEventHandler(m_ProjectViewGrid_ContextMenuOpening);

void m_ProjectViewGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)
           //here I want get menuitem by its header or name and set its IsEnable property to value I want

How can I get the MenuItem by its Header or name and I want to make it disable according to some condition.I tried FindName methods of contextmenu , but I got a Null.

is there anyone who could me how to do that.

1 solution

I don't know much about WPF yet, but try this and let me know if it works:

m_ProjectMenu.Items("item_name_here").IsEnabled = true;
Share this answer
Alimjan Yasin 16-Oct-11 23:55pm    
Hi Macro
unfortunately, it dose not work. Items a collection and only receives numbers as parameter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900