Reputation: 587
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.
Upvotes: 1
Views: 10726
Reputation: 2236
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>
Upvotes: 4
Reputation: 3228
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.
Upvotes: 0
Reputation: 587
I have solved the above issue. I did it in a very simple way.
Simple, but effective!!!
Upvotes: 2
Reputation: 5691
here are some other events by xamdatagrid.
SelectedItemsChanged
SelectedItemsChanging
RecordActivating
RecordActivated
these might help you.
Upvotes: 2
Reputation: 6466
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} />
Upvotes: -2