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