MVVM 消息传递或事件或其他什么选项?
我在 MainViewModel 中有一个菜单,现在在选择特定的菜单项时我想更新已加载的视图的数据。
即,虽然 MainViewModel 中有该 viewModel 的实例,但当我尝试通过该实例调用方法并更改数据属性时,它不会显示视图中的更改。而当我使用该 viewModel 视图上的按钮通过中继命令调用该方法时,会发生相同的更改。
现在我需要从 MainViewModel 调用该 viewModel 的中继命令,我想这会解决问题,但如何做到这一点?什么是最简单的方法。我需要使用消息传递吗?
I have a menu in MainViewModel, now on selection of a particular menuItem I wanted to update data of a view which is already loaded.
i.e. although there's an instance of that viewModel in MainViewModel, when I try to invoke the method thru that instance and change the data property, it doesnt show the changes in the view. Whereas same changes occur when I invoke that method through relay command using a button on that viewModel's view.
Now its like I need to invoke relay command of that viewModel from MainViewModel, I guess that will fix the problem, but how to do that? what's easiest way. Will i need to use messaging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了 MVVM Light Messenger 类,它非常简单和优雅(保持 ViewModel 松散耦合)!最重要的是它有效
I tried MVVM Light messenger class, its quite straightforward and elegant (keeps ViewModels loosely coupled)!! and most importantly it works