Reputation: 6557
I have a WPF/MVVM application with a DataGrid on a window. I want to call a method when the user double clicks on a row in the DataGrid.
How can I bind the DblClick event of the DataGrid to my ViewModel?
Upvotes: 1
Views: 429
Reputation: 132548
I prefer to use AttachedCommand Behaviors, which allow you to attach a Command to just about any UI Event
For example,
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="local:CommandBehavior.Event" Value="MouseDoubleClick" />
<Setter Property="local:CommandBehavior.Command" Value="{Binding MyDoubleClickCommand" />
<Setter Property="local:CommandBehavior.CommandParameter" Value="{Binding }" />
</Style>
Upvotes: 2