This is a migrated thread and some comments may be shown as answers.

Using HierarchicalDataTemplate in a context menu

2 Answers 92 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Nic
Top achievements
Rank 1
Nic asked on 10 Feb 2009, 06:15 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 12 Feb 2009, 09:40 AM
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.
0
Nic
Top achievements
Rank 1
answered on 12 Feb 2009, 04:10 PM
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

Tags
Menu
Asked by
Nic
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Nic
Top achievements
Rank 1
Share this question
or