如何从多个视图模型更新状态栏?
我有一个带有状态栏和多个用户控件的主窗口。每个用户控件都有一个视图模型。如何从多个视图模型绑定/更新状态栏文本?
I have MainWindow with a statusbar and multiple user controls in it. Each user control has a viewmodel. How do I bind/update the statusbar text from multiple viewmodels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个很简单,我自己也用过。
实现 Messenger系统并给它一个 Singleton 实例,例如... StatusBarMessenger
MainWindow View-Model:
所有需要向状态栏发送文本的VM可能会执行以下操作:
This is a simple one that I have used myself.
Implement a Messenger system and give it a Singleton instance, say... StatusBarMessenger
MainWindow View-Model:
All VM that requires to send text to the status bar may do the following:
如果您使用 PRISM,则可以使用其 EventAggregator 发布(从用户控件)消息并在 StatusBar VM 中订阅这些消息。
If you are using PRISM then you can use its EventAggregator to Publish (from your user controls) messages and in StatusBar VM Subscribe to those messages.