for example i have used a Student class below which implements "INotifyPropertyChanged" as shown below.
public class Student : INotifyPropertyChanged
{
private string studentID = string.Empty;
public string StudentID
{
get { return studentID; }
set
{
studentID = value;
OnPropertyChanged("StudentID");
}
}
private string fName = string.Empty;
public string FirstName
{
get { return fName; }
set
{
fName = value;
OnPropertyChanged("FirstName");
}
}
private string lName = string.Empty;
public string LastName
{
get { return lName; }
set
{
lName = value;
OnPropertyChanged("LastName");
}
}
private int totalMark = 0;
public int TotalMark
{
get { return totalMark; }
set
{
totalMark = value;
OnPropertyChanged("TotalMark");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
public class StudentCollection : ObservableCollection<student>
{
}
and a public property for StudentCollection
public StudentCollection studentCollection = new StudentCollection();
and added value for that collection and assigned to the grid
studentCollection.Add(new Student { StudentID = "NK", FirstName = "Navin", LastName = "Kumar", TotalMark = 350 });
studentCollection.Add(new Student { StudentID = "RK", FirstName = "Ram", LastName = "Kumar", TotalMark = 350 });
studentCollection.Add(new Student { StudentID = "PK", FirstName = "Prem", LastName = "Kumar", TotalMark = 350 });
studentDG.ItemsSource = studentCollection;
on some button click i am updating the mark value as below
private void OnUpdateMarkClicked(object sender, RoutedEventArgs e)
{
foreach (Student item in studentCollection)
{
item.TotalMark += 1;
}
}
let me know if it works