//假设变动的属性是“IsChanged”,
List lstDataChanged = new List();
//赋值省略
this.dataGrid.ItemsSource = lstDataChanged;
private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataChangedViewModel mvm = dataGrid.SelectedItem as DataChangedViewModel;
if (mvm.IsChanged.Equals("False"))
{
foreach (DataChangedViewModel item in dataGrid.Items)
{
if (item.Id == mvm.Id)
{
item.IsChanged= "True";
}
}
}
}
public class DataChangedViewModel
: INotifyPropertyChanged
//实体类需要实现INotifyPropertyChanged 接口
{
public event PropertyChangedEventHandler PropertyChanged;
private string isChanged;
public int RowNum { get; set; }
public long Id { get; set; }