I would like to add a ContextMenu to objects in a ListBox.
These objects have a DataTemplate. I got it to add a ContextMenu to the DataTemplate so it was displayed on each item.
But how can I react to any Click Event
I tried to use <MenuItem Click="OnItemMenuClick" /> but how can I get a reference to the data the ContextMenu lies on top Parent properties point to nothing ...

ContextMenu and Data?
Kevin Prendergast
This will work for me but isn't it possible to bind a MenuItem to its dataitem at all
I want to customize the context menu on the dataitem's properties but can't see a way how I can do it e.g. by DataTriggers :(
Shree S
This actually sounds like what I would like to do in some cases as well. I would like to use a data template to place a number of UI related objects in the display that have interaction methods. I would then like to bind the events and properties of the UI to these ViewModel objects. The property part works fine, but the events part is a work in progress.
paul rees
britttd
DSH_msn
I'd experiment with it some more myself before recommending this solution, but I'm in the middle of a release today and don't have the time. Be sure to let us know how that works out for you!
Cheers,
Drew
Golf67
So you're saying you want to populate the context menu instance with items based on it's specific state when the user clicks to show the menu, right I imagine that's the case since I can't think of any other explanation for wanting to bind the click of each item. However, if that is the case then you can do the very same thing by handling the event at the ListBox level. You can get at the SelectedItem in the event handler and check it's state to figure out what ContextMenu (or what options on a ContextMenu) to show from there.
Does this not work for you If not, can you give some more detail
HTH,
Drew
Yuri Kuleshov
So I can't use EventSetters on the Template ...