I have a context menu.
the context menu has two levels : first level and from it exit second level.
I want a click event on the first level .
what I have now is when I click on the first level, the child(second level) opens,
and then when I click on an item on the second level, the event that's assigned to
the first level occurs.
I want a click event on the first level .
The code:
<StackPanel x:Name="LayoutRoot" Background="White">
<RadioButton Content="Click Me to Open the RadContextMenu">
<telerikNavigation:RadContextMenu.ContextMenu >
<telerikNavigation:RadContextMenu EventName="Click" x:Name="radContextMenu1" ShowDelay="1:0:0">
<telerikNavigation:RadMenuItem Header="Item 1" x:Name="firstLevel">
<telerikNavigation:RadMenuItem Header="Item 2" x:Name="secondLevel" />
</telerikNavigation:RadMenuItem>
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
</RadioButton>
</StackPanel>
public
partial class Page : UserControl
{
public Page()
{
InitializeComponent();
firstLevel.Click +=
new RoutedEventHandler(firstLevel_Click);
}
void firstLevel_Click(object sender, RoutedEventArgs e)
{
}
}}
Thanks,
10 Answers, 1 is accepted
RadMenuItem that have subItems do not fire Click event - only MenuItems that don't have subItems fires it. You can use SubmenuOpened or SubmenuClosed event for menuItems that have subItems.
Let me know if this works for you.
Greetings,
Hristo
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.

I have a new question:
How I remove from the context menu child when the child closed?
I try to write in the function :
SubmenuClosed()
for (int i = 0; i <count-1 ; i++)
{
firstLevel.Items.Remove(0);
}
and the items not removed.
How I do it?????
This way of removing items is correct.
Just change count-1 to count in the for declaration because you have only 1 item and 0 < 1-1 is false (you won't enter in the for scope).
Let us know if you need more help.
All the best,
Hristo
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.

I added the items in the function:
SubmenuOpened:
void firstLevel_SubmenuOpened(object sender, RoutedEventArgs e) |
{ |
RadMenuItem tt = new RadMenuItem(); |
tt.Header="eeeeeee"; |
firstLevel.Items.Add(tt); |
count++; |
RadMenuItem t3 = new RadMenuItem(); |
t3.Header = "wwwww"; |
firstLevel.Items.Add(t3); |
count++; |
} |
i removed the items in function:
SubmenuClosed:
void firstLevel_SubmenuClosed(object sender, RoutedEventArgs e) |
{ |
for (int i = 0; i <count ; i++) |
{ |
firstLevel.Items.Remove(0); |
} |
} |
and the items adeed and removed at once.
How I added items in open sub context menu and removed them in closed sub context menu??????
thanks.
Can you elaborate more on your scenario? What you want to achieve?
It is not a common scenario to add MenuItems in SubmenuOpened and remove them SubMenuClosed.
Regards,
Hristo
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.

This is kind of lame. Seems like standard functionality to me. The RadMenu for asp.net (web applications) supports this kind of behavior. We can't use "submenu opened" because the submenu is opened on mouseover. The user needs to be able to mouseover the menu item to see the submenu and then potentially click on the parent menu.

This is kind of lame. Seems like standard functionality to me. The RadMenu for asp.net (web applications) supports this kind of behavior. We can't use "submenu opened" because the submenu is opened on mouseover. The user needs to be able to mouseover the menu item to see the submenu and then potentially click on the parent menu.
The standard WPF menu does not raise Click event for items that have children. This was the case with RadMenu too, but probably an year ago we added the NotifyOnHeaderClick property to RadMenu that allows the cotnrol to raise events when you click on header items (items that have children).
Sincerely yours,
Valeri Hristov
the Telerik team

I am talking about RadMenu for Silverlight, which was designed to work exactly as the standard WPF Menu control.
The WPF/Silverlight RadMenu does not have NavigateUrl property, it has Command/CommandParameter properties that allow you to execute any code, including navigation to other page. By setting NotifyOnHeaderClick the items that have children will execute their commands, as well as raise their Click events.
Best wishes,
Valeri Hristov
the Telerik team