Is there a way to explicitly capture a click on a TreeView item?
Currently, I’m in a position where a TV represents a sort of options menu for users. Ordinarily, I would just use the SelectedItemChanged event on the TV, but there is the possibility of a user re-clicking an item twice in a row which won’t raise this event. I considered the idea of putting an event listener on the stackpanel that contains the items in each node, but the problem is this event fires before a selected item changed on a node. So if you hit the stackpanel, you’ll get the event, but won’t be able to get the associated item. Any ideas on how to get out of this one?
You could handle
MouseLeftButtonUpevent for theTreeView.[EDIT]
You can handle
MouseLeftButtonDown, butSelectedItemwill not be changed yet at that moment. What you can do is to accesse.OriginalSourceto find out what element was clicked. I checked the example below with a tree of<TreeViewItem />, so element wasTextBlock. If you try the code below change the type casting according to your scenario.