MVVM Light 中 viewModel 之间的通信

发布于 2024-10-08 07:49:08 字数 119 浏览 0 评论 0原文

我读到了一些地方,人们使用信使在两个不同的视图模型之间进行通信。但是,当我从主 viewModel 加载所有 viewModel 时,使用主 viewModel 中的这些 viewModel 实例设置属性值是否是错误的做法?

I read couple of places that people use messenger to communicate between two different viewModels. But as I load all viewModels from my main viewModel, is it a wrong practice to set property values using those viewModel instance in main viewModel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2024-10-15 07:49:08

MVVM 非常适合将视图与代码分离,以便您可以获得更好的设计人员-开发人员工作流程(即设计人员可以在混合中编辑视图)和测试(即您可以在无头模式下对没有视图的逻辑进行单元测试)。问题是,当人们开始使用 MVVM 时,他们觉得他们需要所有其他松散耦合模式,IoC、DI 等……

基本上,如果乐意在 ViewModel 之间直接通信(并且是的,我一直这样做),并且您可以测试您的代码(也就是说,如果您选择测试它......它确实是可选的,但不要告诉任何人我这么说过!)。然后,就去做吧。

MVVM is great for separating your view from your code so that you can get a better designer-developer workflow (i.e. designer can edit the view in blend), and testing (i.e. you can unit test your logic without a view, in a headless mode). The problem is, when people start using MVVM they feel they need all the other loose-coupling patterns to, IoC, DI, etc ...

Basically, if you are happy communicating directly between your ViewModels (and yes, I do that all the time), and you can test your code (that is if you choose to test it ... it really is optional, but don;t tell anyone I said that!). Then, go for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文