Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > Handling click not on items?

Answered Handling click not on items?

Feed from this thread
  • Anders avatar

    Posted on Oct 10, 2011 (permalink)

    Hi telerik,

    I wish to handle the event that the user clicks somewhere in the tree where there are no items.

    I would have thought that the MouseDown fired but apparently it doesn't.

    Do you have any advice on what to do?

    Thanks,

    Anders, Denmark

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Oct 13, 2011 (permalink)

    Hello Anders,

     The MouseLeftButton down event is handled by other RadTreeView's events. So you have to attach to it by the UIElement.AddHandler() method providing ability to use handled events:

    this.ExplorerTree.AddHandler(RadTreeView.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ExplorerTree_MouseLeftButtonDown), true);
    You can also find this realized in the attached solution. Please let us know if this is what you expect. Best wishes,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Attached files

    Reply

  • Anders avatar

    Posted on Oct 13, 2011 (permalink)

    Hi Petar,

    Yes, this way the event fires just fine!

    However, I need to react only to clicks outside the tree items.

    Can I translate the position of the click to an item somehow? I've looked at the methods on the treeview without finding any obvious candidates.

    (Furthermore this event fires before the 'ordinary' treeview events making it hard to 'hack' it throgh e.g. registering time stamp om last click on items and then checking in the 'raw' click event).

    Thanks,

    Anders

    Reply

  • Answer Tina Stancheva Tina Stancheva admin's avatar

    Posted on Oct 18, 2011 (permalink)

    Hello Anders,

    In your case it is best to use the MouseLeftButtonDownEvent but check the OriginalSource of the event. If it has a parent of type RadTreeViewItem then the event is fired after clicking an item, but if the original source of the event isn't a RadTreeViewItem element, then the click is somewhere in the RadTreeView but outside an item.

    I modified the solution to illustrate this approach. Please have a look at it and let em know if it works for you.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • Anders avatar

    Posted on Nov 30, 2011 (permalink)

    It took me some time before the task crawled back up the list of backlog items ;)
    Bu the solution works just fine! Thanks for helping out...

    Regrads, Anders, Denmark...

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > Handling click not on items?
Related resources for "Handling click not on items?"

WPF TreeView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]