我正在开发一个WPF项目。为了防止大量的锅炉代码,我正在使用Fody PropertyChanged。这是我的问题的一小部分:
[ImplementPropertyChanged]
public class MyViewModel : MyViewModelBase
{
public bool HasCardSet
{
get
{
return Person != null && Person.Card != null;
}
}
public void SavePerson()
{
Person.Card = new Card();
}
}
[ImplementPropertyChanged]
public class MyViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public Person Person { get; set; }
}
[ImplementPropertyChanged]
public class Person : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public Card Card { get; set; }
}
[ImplementPropertyChanged]
public class Card : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string Name { get; set; }
public ObservableCollection<SomeOtherClass> Items { get; set; }
}
当我致电SavePerson()
时(在MyViewModel
中),它不会触发HasCardSet
属性。
我添加了PropertyChangedNotificationInterceptor
,并看到该属性“卡”在目标“人物”上发生了变化。但是HasCardSet
中的断点不会触发。