# Retrieve the Clicked Item When Opening a RadContextMenu

## Environment

<table>
	<tr>
		<th scope="row">Product Version</th>
		<td>2023.3.1114</td>
	</tr>
	<tr>
		<th scope="row">Product</th>
		<td>RadContextMenu for WPF</td>
	</tr>
</table>

## 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)this.GetValue(ClickedItemProperty); }
        set { this.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)this.GetValue(ClickedItemProperty); }
        set { this.SetValue(ClickedItemProperty, value); }
    }

    protected override void OnOpened(RadRoutedEventArgs e)
    {
        base.OnOpened(e);

        this.ClickedItem = null;
        this.ClickedItem = this.GetClickedElement<TreeListViewRow>();
    }
}
```

## See Also

* [Context Menu Owner](https://www.telerik.com/products/wpf/documentation/controls/radcontextmenu/context-menu-owner)
