我正在为代表递归嵌套类型的类实现MVVM。例如:
class NestedType
{
// Other properties here
public Collection<NestedType> SubElements {get; set;}
}
class NestedTypeViewModel
{
ObservableCollection<NestedType> ModelCollection { ??? }
}
我该如何以可观察的方式公开 Model 集合中的项目呢?(例如,View 将添加、创建和修改子元素)我假设我需要 ViewModel 中的集合是
ObservableCollection<T>
,但 Model 中需要什么呢?我也可以将其作为 ObservableCollection
并直接公开它... 有什么建议吗?
PropertyChanged
,否则不应该有setter。对于集合,通常通过提供私有后备字段和公共getter来使其readonly
。 - H.B.