Сделайте это так
public class ViewModelBase : INotifyPropertyChanged
{
protected void SetProperty<t>(ref T newValue, ref T currentValue, bool notify, string propertyName, params string[] additionalProperties)
{
bool changed = notify && ((newValue != null && !newValue.Equals(currentValue)) || (newValue == null && currentValue != null));
currentValue = newValue;
if (changed)
{
OnPropertyChanged(propertyName);
if (additionalProperties != null)
foreach (string additionalProperty in additionalProperties)
OnPropertyChanged(additionalProperty);
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class MyRealViewModel : ViewModelBase
{public int NumberOfItems {get {return _numItems;} set {SetProperty (ref значение, ref _numItems, true, "NumberOfItems");}}
public bool SomeKindOfFlag
{
get { return _flag; }
set { SetProperty(ref value, ref _flag, false, ""); }
}
public LightSabre WeaponOfChoice
{
get { return _weapon; }
set { SetProperty(ref value, ref _weapon, true, "WeaponOfChoice", "SomeKindOfFlag", "NumberOfItems"); }
}
private bool _flag;
private int _numItems;
private LightSabre _weapon;
}
public class LightSabre
{
открытая строка LightSabreName {get;задавать;}
public override bool Equals(object obj)
{
if (obj != null && obj as LightSabre != null)
return ((LightSabre)obj).LightSabreName == this.LightSabreName;
return false;
}
}
Это извлечено из ответа выше, действительно помогло мне.