I have a ListView/GridView setup and I want to handle a right click on the dislayed items. Is there are Databinding-way of doing this? I have seen complicated workarounds like handling the super-elements event and poking around to find its origin, but that feels awfully bloated for such basic request.
What I'd love to see is something like binding the event to an action of the item's ViewModel - is there a way to do that? Similar to this, but I can't quite wrap my head around how to adapt that to work on a single ListView item (I am not even sure that's possible, tbh).
Rough outline:
<ListView>
<ListView.View>
<GridView />
</ListView.View>
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
</Style>
</ListView.Resources>
</ListView/>
You could try to create a style template for the list view item, and add an attached behaviour to it to handle mouse clicks.
There is a way using the Interactivity assembly form the Blend SDK. It will provide an
EventTrigger
which executes a command when an event is raised.Edit:
A possible solution for your problem could look like this:
View:
ViewModel: