WPF MVVM: How do ViewModels communicate with each other?

喜欢而已 提交于 2019-11-29 23:35:32

One way to have disconnected ViewModels communicate to each other is to use a publish / subscribe mechanism such as PRISMs EventAggregator. However, in a parent / child ViewModel relationship, I think it's fine for the parent to have direct knowledge and control over the child ViewModel.

Personally, I don't think composing a ViewModel out of other ViewModels is a bad practice. I do it all the time. I generally favor composition over inheritance in my ViewModels.

Henk Holterman

The ViewModels usually 'inherit' relationships from the Model. And it's not wrong to add a relation when it makes sense.

It's perfectly OK for a ViewModel to have a property referring to another ViewModel.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!