我对 MVVM 设计有一个大问题。我试图在我的 ViewModel 中捕获我的内部嵌套对象的每个 PropertyChanged,包括它们嵌套对象的进一步属性更改,但我不知道该怎么做。
这是我的结构:
class MyVM
{
public MyVM()
{
this.SomeData = new SomeData();
this.SomeData.NestedObj = new MyNestedDat();
this.SomeData.Str = "This tiggers propertychanged inside MyDat class";
// this triggers propertychanged event inside MyNestedDat class
this.SomeData.NestedObj.Num = 123;
}
// and here should be a method where i catch all possibe propertychanges from my nested objets and their nested objets, how do i do that?
public MyDat SomeData
{
get;
set;
}
}
class MyDat : INotifyPropertyChanged
{
private string str;
public string Str;
{
get { return this.str;}
set
{
this.str = value;
this.PropertyChanged(this, "Str");
}
}
publicMyNestedDat NestedObj
{
get;
set;
}
}
class MyNestedDat : INotifyPropertyChanged
{
private int num;
public int Num
{
get{ return this.num;}
set
{
this.num = value;
this.PropertyChanged(this, "Num");
}
}
}
我怎样才能让它工作?我真的不知道从哪里开始。
MyNestedDat 类抛出 PropertyChanged,MyDat 类抛出 propertychanged,我想在我的视图模型中捕获它们。我怎样才能做到这一点?