Size: 1125
Comment:
|
Size: 610
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
private ObservableCollection<string> _Area = new ObservableCollection<string>(); public ObservableCollection<string> Area |
private BindingList<string> _Area = new BindingList<string>(); public BindingList<string> Area |
Line 11: | Line 11: |
set => SetField(ref _Area, value); | set => SetField<BindingList<string>>(ref _Area, value); |
Line 24: | Line 24: |
I used to use something like this: {{{#!highlight csharp public int test { get { return _test; } set { _test = value; OnPropertyChanged(); } } //... protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { if (PropertyChange != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }}} And before that we just passed in the name. It was kind of a pain. |
Implementing INotifyPropertyChanged
It's changed a lot over the years. Here is the latest iteration that I use.
Toggle line numbers
1 private BindingList<string> _Area = new BindingList<string>();
2 public BindingList<string> Area
3 {
4 get => _Area;
5 set => SetField<BindingList<string>>(ref _Area, value);
6 }
7
8 //...
9
10 public event PropertyChangedEventHandler PropertyChanged;
11
12 protected void SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
13 {
14 field = value;
15 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
16 }