我有一个名为OperatingViewModel的视图模型,其中包含对LevelAListViewModel的引用。每个级别视图模型都代表底层模型中的层次结构。我的问题是,通知OperatingViewModel任何 Level[*]ViewModels 更改的最佳方式是什么?
我已经尝试在父级中收听PropertyChanged事件,效果很好,但看起来不是很干净。
我还尝试将父级作为对子级的引用传递,然后调用一个方法,然后在链上调用它的父级,但同样,这似乎也很糟糕。
class OperatingViewModel : INotifyPropertyChanged
{
LevelAListViewModel LevelACollection { get; set; }
}
class LevelAListViewModel : INotifyPropertyChanged
{
LevelAList _model;
LevelBListViewModel LevelBListViewModel { get; set; }
}
class LevelAViewModel : INotifyPropertyChanged
{
LevelB _model;
LevelBListViewModel LevelBListViewModel { get; set; }
}
class LevelBListViewModel : INotifyPropertyChanged
{
LevelBList _model;
ObservableCollection<LevelBViewModel> LevelBCollection { get; set; }
}
class LevelBViewModel : INotifyPropertyChanged
{
LevelB _model;
LevelCListViewModel LevelCListViewModel { get; set; }
}
class LevelCListViewModel : INotifyPropertyChanged
{
LevelCList _model;
ObservableCollection<LevelCViewModel> LevelCCollection { get; set; }
}
class LevelCViewModel : INotifyPropertyChanged
{
LevelC _model;
LevelDListViewModel LevelDListViewModel { get; set; }
DateTime StartDate
{
get { return _model.StartDate }
set
{
_model.StartDate = value;
OnPropertyChanged("StartDate");
}
}
DateTime EndDate
{
get { return _model.EndDate }
set
{
_model.EndDate = value;
OnPropertyChanged("EndDate");
}
}
}
class LevelDListViewModel : INotifyPropertyChanged
{
LevelD _model;
ObservableCollection<LevelDViewModel> LevelDCollection { get; set; }
}
class LevelDViewModel : INotifyPropertyChanged
{
LevelD _model;
int Price
{
get { return _model.Price}
set
{
_model.Price = value;
OnPropertyChanged("Price");
}
}
}