Hi, as I said in the subject, I have a User control with a XamDataTree that has a XamContextMenu
This user control will be used in different contexts and based on where I use it I need to add some XamMenuItems to the tree context menu.
I've seen on a previous message on the forums how to create the context menu at runtime, but my context menu already contains a number of elements
I just need to retrieve it when I've initialized the control and add some local commands.
For example, on my Context Menu I already have a New, Delete, Cut, Copy, Paste menu item I need to add some specific commands like "Execute my Procedure 1" and more.
The thing I can't find is How to Get the Context Menu from the XamDataTree, there is a ContextMenu property, but it is null,
so I presume there is something different to do to retrieve the Context Menu.
Thank you for your post.
When using a XamContextMenu on the XamDataTree, you need to set it on the ContextMenuManager, and so it does not really reside in the XamDataTree's ContextMenu property. To get this manager, I would recommend using Infragistics.Controls.Menus.ContextMenuService.GetManager(tree); This will get you the context menu manager, and from it, you can get the XamContextMenu from manager.ContextMenu. The reason I included the full name of the ContextMenuService is because there is some ambiguity between the Infragistics version and the System.Windows.Controls version.
I have attached a sample application to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hi Andrew, I've taken a look at your code, and more or less understood it because it gives me a couple of errors
Error 2 Cannot declare a variable of static type 'Infragistics.Controls.Menus.ContextMenuService' D:\DEV\Xamcontextmenu\XamDataTreeContextMenuRetrievalCase\MainWindow.xaml.cs 50 13 XamDataTreeContextMenuRetrievalCase
Is the first one that occurs on this line of code
While waiting for your answer I've made some search and found that the Context Menu can be accessed through the control resources class
XamContextMenu xmnu = (XamContextMenu)this.Resources["TreeContextMenu"];
foreach (XamMenuItem mnu in specificMenu)
Using the above code on the User control hosting the context menu I've been able to update it and add the menu options, I will try also your approach, I just wanted to know if there is any contraindication in the resources approach or if the result is equal.
Using the resources approach is a perfectly viable option, but just keep in mind that by changing the one in the resources, you may change each instance of where you have it being used. If you use the option in the sample project that I had provided you, that will only use the one that belongs to that particular ContextMenuManager.
Also, after reviewing the sample project I sent you, I believe I was trying to test the ambiguity between the ContextMenuService that I had mentioned before, and it appears that I accidentally left that test in the project I sent. This is why you are seeing the "Cannot declare a variable of static type" error. If you go to the click event on the button and remove the instance of ContextMenuService, the error should go away.
Hi Andrew Thank You for your clarification,
this can help if I have the need to use a context menu with different options for different controls,
The error in your project was correct deleting the row where it was raised.
thank you very much for the help!