This is a migrated thread and some comments may be shown as answers.
Can the RadContextMenu be used with Silverlight's ContextMenuService?
2 Answers 12 Views
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 26 Dec 2012, 06:10 PM
I'm new to Silverlight and I'm struggling with something that seems like it should be simple and would appreciate any help that can be provided.

I'm trying to implement the RadContextMenu in our applications and the addition of the RadContextMenu itself has been very simple but we use Silverlight's ContextMenuService to dynamically add items to the context menu (such as adding common functionality from our customized data grid control). I have not been able to figure out a way to continue to use the ContextMenuService and add a RadMenuItem to a RadContextMenu. Are there any examples or documentation that dives into this a bit deeper on how to implement this? I've referred to the Telerik documentation but the examples are simple and don't cover this scenario and I feel at a loss.

Thank you.

2 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 27 Dec 2012, 09:47 AM
Hello,

You are right that most of the menu example are XAML but XAML is usually easily ported to C# and vice-versa. I am sorry for the inconvenience. Here is an example how you can get and set a RadContextMenu to and from and element in code behind:
// To get the context menu from an element:
var currentContextMenu = RadContextMenu.GetContextMenu(this.LayoutRoot);
 
// To create and set a context menu to an element:
var contextMenu = new RadContextMenu();
contextMenu.Items.Add(new RadMenuItem() { Header = "Item 1" });
contextMenu.Items.Add(new RadMenuItem() { Header = "Item 2" });
contextMenu.Items.Add(new RadMenuItem() { Header = "Item 3" });
RadContextMenu.SetContextMenu(this.LayoutRoot, contextMenu);

Where the LayoutRoot is the Grid in XAML of the MainPage. You can substitute it with any other control with x:Name in the XAML of yout MainPage. And the code is placed just after the InitializeComponent method. The only difference from the ContextMenuService is that we have our own attached property "ContextMenu" in the "RadContextMenu" class. The ContextMenuService would not work with our RadContextMenu.

Kind regards,
Pana
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael
Top achievements
Rank 1
answered on 04 Jan 2013, 09:07 PM
Thank you so much!
Asked by
Michael
Top achievements
Rank 1
Answers by
Pana
Telerik team
Michael
Top achievements
Rank 1
Share this question
or