New to Telerik UI for WPF? Start a free 30-day trial
Retrieve the Clicked Item When Opening a RadContextMenu
Updated on Sep 15, 2025
Environment
| Product Version | 2023.3.1114 |
| Product | RadContextMenu for WPF |
Description
Retrieve the clicked item when the RadContextMenu is opened.
Solution
You can derive from the RadContextMenu class and add an additional dependency property.
Deriving from the RadContextMenu class and adding an additional dependency property
C#
public class ExtendedContextMenu : RadContextMenu
{
public static readonly DependencyProperty ClickedItemProperty =
DependencyProperty.Register("ClickedItem", typeof(FrameworkElement), typeof(ExtendedContextMenu), new PropertyMetadata(null));
public FrameworkElement ClickedItem
{
get { return (FrameworkElement)GetValue(ClickedItemProperty); }
set { SetValue(ClickedItemProperty, value); }
}
}To assign a value to the dependency property, override the OnOpened method and call the GetClickedElement method. This method will allow you to retrieve the first element of the given type at the click point coordinates.
In the following example, the custom RadContextMenu is used in the RadTreeListView control and a reference to the clicked TreeListViewRow instance is retrieved in the OnOpened method.
Retrieving the clicked TreeListViewRow instance inside the OnOpened method of the custom RadContextMenu
C#
public class ExtendedContextMenu : RadContextMenu
{
public static readonly DependencyProperty ClickedItemProperty =
DependencyProperty.Register("ClickedItem", typeof(FrameworkElement), typeof(ExtendedContextMenu), new PropertyMetadata(null));
public FrameworkElement ClickedItem
{
get { return (FrameworkElement)GetValue(ClickedItemProperty); }
set { SetValue(ClickedItemProperty, value); }
}
protected override void OnOpened(RadRoutedEventArgs e)
{
base.OnOpened(e);
this.ClickedItem = null;
this.ClickedItem = this.GetClickedElement<TreeListViewRow>();
}
}