Handling click not on items?

5 posts, 1 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 10 Oct 2011 Link to this post

    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
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 13 Oct 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 13 Oct 2011 Link to this post

    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
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 18 Oct 2011 Link to this post

    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 >>

  6. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 30 Nov 2011 Link to this post

    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...
Back to Top
UI for WPF is Visual Studio 2017 Ready