Custom RadContextMenu per cell

2 posts, 0 answers
  1. Marcel
    Marcel avatar
    41 posts
    Member since:
    Jan 2014

    Posted 05 May Link to this post

    Hello,

    I want to have a custom contextmenu per cell, I implemented this succesfully with the example given in this thread.

    Now I want to add the functionality that the contextmenu will be displayed based on the row where the cursor is and the contextmenu is called, in another thread they point me to the RadContextMenu example of the Telerik Demos. 

    So I created a custom class which inherits from the RadContextMenu and attach an implementation for the open event:

    protected void GridViewContextMenu_Opened(object sender, RoutedEventArgs e)
    {
        RadContextMenu menu = (RadContextMenu)sender;
        GridViewRow row = menu.GetClickedElement<GridViewRow>();
     
        if (row != null)
        {
            row.IsSelected = row.IsCurrent = true;
            GridViewCell cell = menu.GetClickedElement<GridViewCell>();
            if (cell != null)
            {
                cell.IsCurrent = true;
            }
        }
        else
        {
            menu.IsOpen = false;
        }
    }

     

    created 4 different contextmenus, 1 default and 3 other that depend on the cell where the user calls the contextmenu.

    When I try setting this custom contextmenu in XAML as default for my GridView and as contextmenu for some cells using styles. I receive an InvalidOperationException stating that the given contextmenu is not a valid value for the ContextMenu property?

    It worked with the regular ContextMenu, but when I change my custom ContextMenu to inherit from this class I cant call the function GetClickedElement<GridViewCell>()?

     

    How can I solve this, I dont exactly understand why I get this exception with RadContextMenu and not with a regular ContextMenu.

    Any help would be appreciated.

    Regards,

     

    Marcel

     

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 09 May Link to this post

    Hello Marcel,

    Can you please take a look at the following resources, as the recommended usage of RadContextMenu in conjunction with RadGridView is demonstrated in them.

    -   RadContextMenu and RadGridView MVVM SDK Example.
    -   RadContextMenu for RadGridView SDK Example.
    -   Use RadContextMenu with a RadGridView help topic.

    The SDK Examples can be reviewed through the SDK Samples Browser.

    I hope this helps.

    All the best,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top