Hello,
I'm trying to get a command in my ViewModel executed when the user clicks on a item in a ListView. When I add a ListViewItem
in XAML I can just add a MouseBinding
to its InputBindings
.
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="Test" />
</GridView>
</ListView.View>
<ListViewItem Content="Item 1" >
<ListViewItem.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding DoubleClickCommand}" />
</ListViewItem.InputBindings>
</ListViewItem>
</ListView>
But how can this be achived in a databound ListView?
<ListView ItemsSource="{Binding Patients}">
<ListView.View>
<GridView>
<GridViewColumn Header="Test" />
</GridView>
<!-- How to set the MouseBinding for the generated ListViewItems?? -->
</ListView.View>
I already got a solution by defining ListViewItem
style and replacing the ControlTempalte
of the ListViewItem
. Though, I hope there is an easier solution.
Sincerely, Michael