4

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>
Carlos H
  • 694
  • 1
  • 7
  • 16

3 Answers3

6

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

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
2

Take a look at Attached command behaviours (http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/). They allow to bind commands to events.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
Nikolay
  • 3,658
  • 1
  • 24
  • 25
0

You can create a behavior to add a binding between your ViewModel’s Command and the Double Click event of the Grid.

See the following post for more information:

http://blogs.infragistics.com/forums/p/67749/343013.aspx#343013