How to get a WPF command to execute on row double click of the Infragistics WPF datagrid?

Carlos H picture Carlos H · Mar 29, 2012 · Viewed 9.5k times · Source

I have a WPF XamDataGrid (I'm using the MVVM pattern, xaml below) and I need it to show the record details in another window when the user double clicks on a row. I have the command which gets the job done, but I don't know how to fire it up as I do with buttons. I want to be able to execute the command when the user double clicks a row, so I need to send the double clicked row (or its ID) as a parameter to the comand. Is it possible?

<igDP:XamDataGrid DataSource="{Binding SomeList}">
            <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings AutoGenerateFields="False"/>
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout >
                    <igDP:FieldLayout.Fields>
                        <igDP:Field  Name="ObjectId" Label="Id" Width="Auto"/>
                        <igDP:Field  Name="Description" Label="Object Description" Width="Auto"/>
                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>

Answer

user1331279 picture user1331279 · Apr 13, 2012

I use MVVM pattern too and write such as:

<igDP:XamDataGrid ItemsSource={Binding Path=StaffList, Mode=OneWay}>
  ...
  <igDP:XamDataGrid.InputBindings>
    <MouseBinding MouseAction="LeftDoubleClick" 
                  Command="{Binding Path=EditStaffCommand, Mode=OneWay}" 
                  CommandParameter="{Binding Path=DataItem}"/>
  </igDP:XamDataGrid.InputBindings>
  ...
</igDP:XamDataGrid>

Where EditStaffCommand and StaffList - properties from view model