AnushaD

I have the hierarchical data template defined for the tree view. When I click on any node if show me controls that the mouse pointer is on. I need to find if the Item was clicked to start the Drag operation. As the Item is a datatemplate ( made of checkbox image and textblock) it shows the control the mouse pointer is on like checkbox or the image or the textblock. Is there anyway to check if the mouse in on a Item as a whole.




Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

neil mosafi

Hmm you should be able to use VisualTreeHelper.FindAncestor to walk the tree to find the TreeViewItem which was clicked.

There's probably a better way but that should work!

Regards
Neil




Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

AnushaD

Thanks. I was able to find the TreeViewItem using VisualTreeHelper.GetParent. FindAncestor is not a method on the VisualTreeHelper




Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

neil mosafi

Ooops good point!

FindAncestor is actually a little helper method I use in my app which recursively calls VisualTreeHelper.GetParent() with a Predicate to find the ancestor.

Sorry about that but looks like you got the right idea anyway!

Regards
Neil




Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

neil mosafi

Actually come to think of it you might be able to use the bubbling of events to detect the click on the TreeViewItem, e.g

<TreeView TreeViewItem.Click="HandleTreeViewItemClick" />

I believe in the routed event, the e.Source property should be the TreeViewItem...






Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

AnushaD

This works..great :)

By the way there is no Click event on the Treeview Item . Its the 'Selected' event that can be used instead.

Thanks once again

Anusha






Re: Windows Presentation Foundation (WPF) Mouse click event on the tree view

neil mosafi

Hmm apologies for my inaccurate advice! I should check these things first but it's getting late!