1

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?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Jerry
  • 6,357
  • 8
  • 35
  • 50
  • See this post [WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?](http://stackoverflow.com/questions/4497825/wpf-mvvm-how-to-handle-double-click-on-treeviewitems-in-the-viewmodel/4498006#4498006) – sll Jan 18 '12 at 19:02
  • Thanks for the link. I liked the last solution using the CodeBehind to link to the Edit Command. Much simpler solution. – Jerry Jan 19 '12 at 18:42

1 Answers1

2

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>
Rachel
  • 130,264
  • 66
  • 304
  • 490