NotifyPropertyChanged

using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; namespace TestDelegate { class Program { static ObservableCollection<SelectedSchoolList> _SelectedSchoolList = new ObservableCollection<SelectedSchoolList>(); static void Main(string[] args) { _SelectedSchoolList.Add(new SelectedSchoolList()); _SelectedSchoolList[0].SchoolName = "Bach Khoa University"; Console.ReadLine(); } } class SelectedSchoolList : INotifyPropertyChanged { private string _schoolName; private string _score; public string SchoolName { get => _schoolName; set { _schoolName = value; NotifyPropertyChanged(); } } public string Score { get => _score; set { _score = value; NotifyPropertyChanged(); } } private ObservableCollection<SelectedStudentList> _electedStudentArray; public ObservableCollection<SelectedStudentList> SelectedStudentArray { get => _electedStudentArray; set { _electedStudentArray = value; NotifyPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; // Add a function to PropertyChanged in class's constructor public SelectedSchoolList() { this.PropertyChanged += (sender, e) => { Console.WriteLine(($"Property changed: {e.PropertyName}")); }; } private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } public class SelectedStudentList { public int StudentID { get; set; } public string StudentName { get; set; } public string IndividualScore { get; set; } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.