GetClickedElement<T>() returns false item

2 posts, 1 answers
  1. Daniel
    Daniel avatar
    3 posts
    Member since:
    May 2011

    Posted 24 May 2011 Link to this post


    I have the following structure in my application:
                    -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?

  2. Answer
    Hristo avatar
    832 posts

    Posted 27 May 2011 Link to this post

    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,
    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
Back to Top