9
votes

Silverlight 4 has a new ContextMenu control in the latest toolkit.

I can't find any examples anywhere on how to reliably use this ContextMenu on a DataGrid row. Theres a tonne of context menus out there but I want to use the new version from the toolkit.

I'd like to be able to set context menus for rows as well as cells.

The only way I've found is to manually create the menu on right click and show it, but I'd like to do it in XAML.

Note: You need to currently use this workaround to avoid binding problems when using ContextMenu in XAML for a datagrid cell.

2
If you got an answer to this question would you need an answer that other question? If you got an answer to that question would you need an answer to this one? It seems to me that these two questions are the same, since there is more detail in the other I'll vote to close this one and try to help you in the other one.AnthonyWJones
@anthonywjones - i realize they're very close, but i think someone searching to actually do the basic task of adding a contextmenu to a datagrid row or column would be more likely to stumble on this question. they wouldn't be bothered about the problem i was having (or even know about it) - they'd just want a solution.Simon_Weaver
note: i've changed this question slightly now I'm asking for a bounty. i've solved the problem I had (with thanks to david anson at microsoft) with binding problems. but the question remains whether or not its possible to use XAML to create a contextmenu for a datarow - the entire row not just a cellSimon_Weaver

2 Answers

6
votes

The developer of the Toolkit's ContextMenu wrote this article, specifically talking about using it with a DataGrid Delay's Blog

0
votes

You can use this open source multi-level menu and context menu as alternative:

www.sl4popupmenu.codeplex.com

The demo on the main page shows how to do it in code. But you can also create the menu anywhere in your XAML like any other control and then associate it with the Datagrid using the RightClickElements property. The control will then handle everything else for you.