Handling Item Clicks
Environment
| Product Version | 2026.1.415 |
| Product | RadContextMenu for WPF |
Description
Handle a click on a RadContextMenu item by subscribing to the RadMenuItem Click event or the RadContextMenu ItemClick event.
Solution
Choose the Click event for a specific menu item or the ItemClick event when one handler should process clicks from child menu items.
There are two ways to handle a click on an item:
Handle the Click Event of the RadMenuItem
Handling the Click event of each item is the straight-forward way. But it has some disadvantages:
-
You have to attach an event handler to each item. This makes the code harder to maintain.
-
It is not suitable when having dynamic items.
If the RadMenuItem is in the role of a header (has child items), the ItemClick event will not be raised unless the NotifyOnHeaderClick property is set to True.
Here is an example of an event handler attached to the Click event and how to get the instance of the clicked item.
Attach RadMenuItem Click Handlers
<telerik:RadContextMenu xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<telerik:RadMenuItem Header="Item 1"
Click="RadMenuItem_Click" />
<telerik:RadMenuItem Header="Item 2"
Click="RadMenuItem_Click" />
<telerik:RadMenuItem Header="Item 3"
Click="RadMenuItem_Click" />
</telerik:RadContextMenu>
Handle the Click Event in C#
private void RadMenuItem_Click( object sender, RadRoutedEventArgs e )
{
RadMenuItem item = sender as RadMenuItem;
//implement the logic regarding the instance here.
}
The handler receives the clicked RadMenuItem through the sender argument.
Handle the ItemClick Event of the RadContextMenu
Handling the ItemClick event of the RadContextMenu gives you more flexibility, as it fires each time a child menu item is clicked. This approach is the most suitable when having a dynamic data scenario.
If the RadMenuItem is in the role of a header (has child items), the ItemClick event will not be raised unless the NotifyOnHeaderClick property is set to True.
Here is an example of an event handler attached to the ItemClick event and how to get the instance of the clicked item.
Attach the RadContextMenu ItemClick Handler
<telerik:RadContextMenu xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
ItemClick="radContextMenu_ItemClick">
<telerik:RadMenuItem Header="Item 1" />
<telerik:RadMenuItem Header="Item 2" />
<telerik:RadMenuItem Header="Item 3" />
</telerik:RadContextMenu>
Handle the ItemClick Event in C#
private void radContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
{
RadMenuItem item = e.OriginalSource as RadMenuItem;
//implement the logic regarding the instance here.
}
The ItemClick handler receives the clicked item from e.OriginalSource.