I am a problem with the event in WPF. Say I have a underlying data model and a tree view to present the data. The simplest thing I want to do is, when I click on one item, I would do something with underlying data associated with that item.
I tried using the MouseLeftButtonDown event of the Textblock, but then the sender object is just the Textblock itself and I cannot get access to the underlying data.
Now I also tried using the MouseLeftButtonDown event of the TreeViewItem like this:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseLeftButtonDown" Handler="itemClicked"/>
</Style>
</TreeView.ItemContainerStyle>
But I did not get the handler called.
So how exactly should I do this? Is there some kind of standard approach?
MouseDoubleClick, but I read the document about it, and it will be called whenever wherever the user double clicks on the control (tree view), and again the sender is then the tree view, but not theTreeViewItem.