views:

733

answers:

3

I understand why this is happening. The bounding box of a parent TreeViewItem includes its children's bounding boxes, so when I am moused over a TreeViewItem, all its parents in the tree are also moused over. Is there something besides IsMouseOver I should be using?

A: 

That sounds like the right event. One thing you can do to prevent MouseOver events is to check the MouseOver events for your TreeViewItems. If your RoutedEventArgs.OriginalSource does not equal the parent, just return and manage your event handlers manually.

public void TreeViewItem_MouseOver(object sender, RoutedEventArgs e)
{
  if (sender != e.OriginalSource) return;
}
Jeff Wain
too bad there is no MouseOver event for a TreeViewItem...
Roel
Sorry about that. I actually realized after writing this that we work with an overridden TreeViewItem class that implements MouseOver. If it does in fact work, Mahop's solution would be elegantly simple.
Jeff Wain
A: 

http://blogs.msdn.com/mikehillberg/archive/2006/09/21/MyTreeViewHelperIsMouseDirectlyOverItem.aspx

this link solved the problem, I did not try the Original Source idea.

Kamiikoneko
+2  A: 

Better - Try This link!!!! (Less than one line of code!!!) http://blogs.msdn.com/hulyap/archive/2008/07/07/mouseover-trigger-for-treeviewitem.aspx

Mahop