Reputation: 770
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>
Upvotes: 4
Views: 10025
Reputation: 61
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
Upvotes: 6
Reputation: 3828
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.
Upvotes: 2
Reputation: 1
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
Upvotes: 0