Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xamdatagrid

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>
like image 611
Carlos H Avatar asked Feb 22 '23 00:02

Carlos H


1 Answers

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

like image 157
user1331279 Avatar answered May 16 '23 07:05

user1331279