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

GetClickedElement<T>() returns false item

1 Answer 78 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 24 May 2011, 03:55 PM
Hi,

I have the following structure in my application:
RadOutlookBar
    -RadOutlookBarItem
        -RadPanelBar
            -RadPanelBarItem
                -RadTreeView (with Items)

So, a RadOutlookBar with a RadOutlookBarItem contains a RadPanelBar with RadPanelBarItems. The RadPanelBarItem contains a RadTreeView with RadTreeViewItems.

In the RadTreeView is also a RadContextMenu.

When I right-clicked on a TreeViewItem of the TreeView, the ContextMenus opened-event is fired and ContextMenu.GetClickedElement<RadTreeViewItem>(); will return the right RadTreeViewItem. Then I click on a MenuItem and the ItemClick-event is fired. So far, so good.

Well when I do this a second time, the ContextMenu.GetClickedElement<RadTreeViewItem>(); returns the RadPanelBarItem which contains the TreeView.
As I see the RadPanelBarItem inherits from the RadTreeViewItem and the documentation says, GetClickedElement<T>() will return the top-most element of T. I think this is an incorrect behavior, because it returns two different elements and the second time the top-most element of T.
The error occurs, when at the first time the ItemClick-event of the ContextMenu was fired, after a MenuItem was clicked.

Got it?

GetClickedElement<T>() should always return the last element (the innermost) of T or am I wrong?

Thanks,
Daniel

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 27 May 2011, 08:31 AM
Hi Daniel,

Just to be clear - on Opened you always get the correct (top most) element but in ItemClick event you get different element, right?
GetClickedElement should be called only in RadContextMenu Opened element. After that mouse moves and you will get different element.

I've attached simple example using your test scenario. In Opened event you always get the correct treeviewitem.
I don't call GetClickedElement at ItemClick event. Instead you should save the clicked element in Opened event in a local variable and clear it on Closed event.

Let us know if you need more information.

All the best,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ContextMenu
Asked by
Daniel
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or