Can the RadContextMenu be used with Silverlight's ContextMenuService?

3 posts, 0 answers
  1. Michael
    Michael avatar
    3 posts
    Member since:
    Oct 2012

    Posted 26 Dec 2012 Link to this post

    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. Pana
    Pana avatar
    748 posts

    Posted 27 Dec 2012 Link to this post


    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,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Michael
    Michael avatar
    3 posts
    Member since:
    Oct 2012

    Posted 04 Jan 2013 Link to this post

    Thank you so much!
Back to Top