Using HierarchicalDataTemplate in a context menu

3 posts, 1 answers
  1. Nic
    Nic avatar
    32 posts
    Member since:
    Oct 2008

    Posted 10 Feb 2009 Link to this post

    Hi,

    With Hristo's help, I have got a menu working with the HierarchicalDataTemplate.See http://www.telerik.com/community/forums/silverlight/menu/radmenu-and-hierarchicaldatatemplate.aspx

    I now want to do the same with the RadContextMenu, and have applied the same concept by creating a derived RadContextMenu (named MyContextMenu) and overriding the same methods (inserting the same code).

    However, when I then try to attach my context menu to an element like so:

    myTextBlock.SetValue(MyContextMenu.ContextMenuProperty, contextMenuInstance);

    then an ArgumentNullException is thrown from the above line (Value cannot be null. Parameter name: meth).

    Is there perhaps some thing I should be initializing in my derived class MyContextMenu's constructor?

    Thanks,
    Nic





  2. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 12 Feb 2009 Link to this post

    Hi Nic,

    This is indeed a bug and will be fixed for the next (Q1) release. I have updated your Telerik Points.
    As a workaround for the moment you can define OnEventTriggered method in your inherited context menu like this:

    public class MyContextMenu : RadContextMenu  
    {  
        public static void OnEventTriggered(object sender, EventArgs e)  
        {  
            FrameworkElement fe = sender as FrameworkElement;  
            if (fe != null)  
            {  
                RadContextMenu menu = GetContextMenu(fe);  
                if (menu != null)  
                {  
                    menu.IsOpen = false;  
                    bool modifierKeyPressed = (Keyboard.Modifiers & menu.ModifierKey) == menu.ModifierKey;  
                    if (modifierKeyPressed)  
                    {  
                        menu.IsOpen = true;  
                    }  
                }  
            }  
        }  

    Let me know if this works for you.

    Best wishes,
    Hristo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Nic
    Nic avatar
    32 posts
    Member since:
    Oct 2008

    Posted 12 Feb 2009 Link to this post

    Hi Hristo,

    Thanks for pointing out this as a bug and providing a temporary workaround to keep me going until the Q1 release. I'm looking forward to that.

    Much appreciated!
    Nic

Back to Top