Infragistics XamDataGrid WPF MVVM SelectionChanged

Anshuman picture Anshuman · May 31, 2012 · Viewed 10k times · Source

We are implementing a MVVM architecture in our WPF application. We want to use the Infragistics XamDataGrid but kind of lost about implementing the selection changed event on the view model layer.

Any help will be greatly appreciated.

We need a solution urgently!!!

Anshuman Chakravarty Humana Inc.

Answer

Rajnikant picture Rajnikant · Jan 21, 2016

For Infragistic v11.2 XamlDataGrid has property called ActiveDataItem that represent current dataitem bound to the row.

What you can do is create property in your ViewModel and Bind that to ActiveDataItem of XamlDataGrid as Below and observe the changes as below.

<igDataPresenter:XamDataGrid ActiveDataItem="{Binding ActiveItem, Mode=TwoWay}" >

My Scenario: I wanted to fire command on my dataItem bound to individual grid row on doubleclick on individual rows, Below xaml code is working for me,

        <igDataPresenter:XamDataGrid x:Name="DemoGrid" 
                    DataSource="{Binding Path=Items, Mode=OneWay}"
        >
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
          <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=igDataPresenter:XamDataGrid}, Path=ActiveDataItem.ViewCommand}"></i:InvokeCommandAction>

        </i:EventTrigger>
      </i:Interaction.Triggers>