Open
Description
Before:
public class ViewModel : INotifyPropertyChanged
{
private readonly Dictionary<string, string> map = new Dictionary<string, string>{ { "1", "one" } };
public event PropertyChangedEventHandler PropertyChanged;
public string this[string index]
{
get => this.map[index];
set
{
this.map[index] = value;
this.OnPropertyChanged();
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
After:
public class ViewModel : INotifyPropertyChanged
{
private readonly Dictionary<string, string> map = new Dictionary<string, string>{ { "1", "one" } };
public event PropertyChangedEventHandler PropertyChanged;
public string this[string index]
{
get => this.map[index];
set
{
this.map[index] = value;
this.OnPropertyChanged("Item[]");
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
When using [CallerMemberName]
Item
is passed as name and it does not work with bindings.