I have an event issue in WPF. Say I have a basic data model and a tree view for representing data. The simplest thing I want to do is when I click on one element, I would do something with the underlying data associated with that element.
I tried to use the MouseLeftButtonDown event for a Textblock , but then the sending object is only a Textblock , and I cannot access the underlying data.
Now I also tried to use the MouseLeftButtonDown event for the TreeViewItem as follows:
<TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <EventSetter Event="MouseLeftButtonDown" Handler="itemClicked"/> </Style> </TreeView.ItemContainerStyle>
But I did not get a handler.
So how exactly should I do this? Is there any standard approach?
Thanks, advanced!
source share