Hi
How can two infragistics controls share the same context menu. Say, I have xamdatatree and xamdiagram in a window and I wanted to have same context menu for both controls?
Thanks.
Hello Abs,
In order to have the XamDiagram and the XamDataTree share essentially the same context menu, I would recommend defining your XamContextMenu as a resource and giving it an x:Key. This will allow you to access it by the key that you give it when you set up the ContextMenuManager needed to apply your XamContextMenu to a particular control. The ContextMenuManager has a ContextMenu property, and by defining your XamContextMenu as a resource, you can apply it using a StaticResource. An example XamDiagram using this method could look like the following:
<ig:XamDiagram> <ig:ContextMenuService.Manager> <ig:ContextMenuManager ContextMenu="{StaticResource contextMenu}"/> </ig:ContextMenuService.Manager></ig:XamDiagram>
I have attached a sample project to demonstrate the above. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thanks, it works as expected.
Thank you for your response. I am glad that the sample project works for you on this matter.
Andrew one more question, how can this context menu be used in user controls of within same application. Lets say I have mainwindow which has two columns; each column is populated with user control. One user control (separate file) has XamDataTree and other has XamDiagram. When I reference as mentioned earlier it fails due to null reference exception
I am rather unsure why you are receiving a NullReferenceException on this matter, but I would recommend in this case, to place the XamContextMenu in a spot where both of the elements within the UserControls can access the XamContextMenu via its key.
For example, if you keep the XamContextMenu in the Grid.Resources like in the original sample project I had sent you, then the XamDiagram and the XamDataTree won't be able to access it after being moved to their own separate UserControls. However, if you were to move the XamContextMenu to a section like your Application.Resources in your App.xaml file, both of these controls would be able to access the XamContextMenu again and you shouldn't see any sort of exceptions.
I have attached a modified version of the original sample project I had sent you to demonstrate the above.
Hi Andrew, thank you very much for your prompt response, I had moved XamContextMenu to resources section in MainWindow and user controls were not able to resolve this. However now I have moved these to application resources as you suggested and it works perfectly.
Thanks again.
I am glad to see that the recommendations I had given have resolved this issue for you.