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

Get underlying TreeViewItem on MouseEnter

2 Answers 102 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Raj
Top achievements
Rank 1
Raj asked on 09 Mar 2009, 06:38 PM
When I hover over an item I would like to get the underlying TreeViewItem. Is this possible? Additionally, I would like to change the look of the item on hover. Do you have any good articles that would show the best method of doing this. Any help is greatly appreciated.

Thanks,
Raj

2 Answers, 1 is accepted

Sort by
0
Accepted
Tihomir Petkov
Telerik team
answered on 13 Mar 2009, 10:41 AM

Hi Raj,

Currently there is no nice and easy way of knowing when the user moves the mouse pointer over a treeview item. If you only want to change the visual appearance of the item, then you can just edit the control template - there is a default MouseOver visual state which you can change to your liking. However, if you want to execute some custom logic when the mouse cursor moves over a treeview item, here is how you can do that:

<telerikNavigation:RadTreeView MouseMove="treeView_MouseMove">

private void treeView_MouseMove(object sender, MouseEventArgs e)
{
 FrameworkElement element = e.OriginalSource as FrameworkElement;
 if (element != null)
 {
  while (VisualTreeHelper.GetParent(element) != null)
  {
   element = VisualTreeHelper.GetParent(element) as FrameworkElement;
   RadTreeViewItem item = element as RadTreeViewItem;
   if (item != null)
   {
    // Do something

    // You have to return here because otherwise the method will traverse
    // the whole visual tree on every mouse move and there will be performance
    // implications
    return;
   }
  }
 }
}

I hoe this answers your question. Let me know if you have further questions.

Regards,

Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Raj
Top achievements
Rank 1
answered on 17 Mar 2009, 05:29 PM
Thank you - will try it out.
Tags
TreeView
Asked by
Raj
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Raj
Top achievements
Rank 1
Share this question
or