Question

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.

Was it helpful?

Solution 3

I have solved the above issue. I did it in a very simple way.

  1. Bind the ActiveCell property of the XamGrid to an object type property in the VM.
  2. In the setter of the property, call a method and pass the object.
  3. Inside the method, cast the object to Infragictics.Windows.Cell type variable.
  4. Use the Infragistics.Windows.Cell object's Record.Index to find the Selected Index.
  5. Using that index, find the row selected from the original collection/data source to which the xamdatagrid was binded.

Simple, but effective!!!

OTHER TIPS

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>

here are some other events by xamdatagrid.

SelectedItemsChanged
SelectedItemsChanging

RecordActivating
RecordActivated

these might help you.

If you are looking to be able to bind the selected items using MVVM then I would recommend using a behavior to accomplish this. Devin Rader wrote a blog post that covers synchronizing values between a view model for and the UI for selection and you may be able to use something similar to know when the selection has changed within your view model.

Let me know if you have any questions with this matter.

I've never used the data grid that you're asking about but you can bet it works the same as everything else.

in the ViewModel that you're binding the view to there will be a property called SelectedItem or something to that effect.

public object SelectedItem
{
    get { return (object)GetValue(SelectedItemProperty); }
    set { SetValue(SelectedItemProperty, value); }
}

// Using a DependencyProperty as the backing store for SelectedItem.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedItemProperty =
    DependencyProperty.Register("SelectedItem", typeof(object), typeof(ownerclass), new UIPropertyMetadata(0));

in the xaml you can probably bind the grids Selected property to that dependency property.

<XamDataGrid ItemsSource={Binding Items} SelectedItem={Binding SelectedItem, UpdateSourceTrigger=PropertyChanged} />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top