Когда элементы сбора данных реализуют интерфейс INotifyPropertyChanged, свойство, связанное с полем, будет обновлено автоматически, как в примере ниже.Но если необходимо получить событие, когда пользователь изменяет значение ячейки, можно использовать обработчик события CellChanged.Надеюсь, что это поможет.
XAML:
<igDP:XamDataGrid DataSource="{Binding NamesCollection}" AutoFit="True" GroupByAreaLocation="None" CellChanged="XamDataGrid1_CellChanged">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field Name="FirstName" Label="First Name" AllowEdit="False"/>
<igDP:Field Name="LastName" Label="Last Name">
<igDP:Field.Settings>
<igDP:FieldSettings DataItemUpdateTrigger="OnCellValueChange" />
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Кодовый код:
using System.Windows;
namespace XamDataGridUpdateTrigger
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
NamesCollection.Add(new NamesItem("Sport", "Chief"));
InitializeComponent();
}
public NamesModel NamesCollection
{
get { return (NamesModel)GetValue(NamesProperty); }
set { SetValue(NamesProperty, value); }
}
// Using a DependencyProperty as the backing store for Names. This enables animation, styling, binding, etc...
public static readonly DependencyProperty NamesProperty =
DependencyProperty.Register("NamesCollection", typeof(NamesModel), typeof(MainWindow), new PropertyMetadata(new NamesModel()));
private void XamDataGrid1_CellChanged(object sender, Infragistics.Windows.DataPresenter.Events.CellChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"{e.Cell}");
}
}
}
Модель данных:
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
namespace XamDataGridUpdateTrigger
{
public class NamesModel : NamesDataCollection
{
public NamesModel()
{
}
}
public class NamesDataCollection : ObservableCollection<NamesItem>
{
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
base.OnCollectionChanged(e);
}
}
public class NamesItem : INotifyPropertyChanged
{
public NamesItem()
{
}
public NamesItem(string fname, string lname)
{
FirstName = fname;
LastName = lname;
}
private string _firstName;
public string FirstName
{
get { return _firstName; }
set { if (_firstName != value) { _firstName = value; OnPropertyChanged("FirstName"); } }
}
private string _lastName;
public string LastName
{
get { return _lastName; }
set { if (_lastName != value) { _lastName = value; OnPropertyChanged("LastName"); } }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
this.PropertyChanged?.Invoke(sender, e);
}
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
OnPropertyChanged(this, e);
}
protected virtual void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}