MVVM Mediator 多个实例
有人可以解释一下中介模式如何与多个实例一起工作吗?
我在视图中的代码:
public MyView() {
Mediator.Register("CloseWindow",()=>Close());
}
和在 ViewModel 中:
public SomeMethod() {
Mediator.Notify("CloseWindow");
}
只要 View - ViewModel 对只有一个实例,就可以找到此代码。
多个实例如何解决?
Can someone explain how the mediator pattern works with multiple instances.
My code in the view:
public MyView() {
Mediator.Register("CloseWindow",()=>Close());
}
and in the ViewModel:
public SomeMethod() {
Mediator.Notify("CloseWindow");
}
This works find as long as there is only one instance of the View - ViewModel pair.
How do I solve it with multiple instances?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你的中介模式的特定实现是如何工作的,但在我的模式中你可以发送更多的信息而不仅仅是字符串。
例如:
在 ViewModel 中:
在此示例中,ViewModel 将其自身作为参数传递给视图。然后视图可以检查消息是否是从其视图模型发送的。
I don't know how your particular implementation of the mediator pattern works, but in mine you can send more information than just strings.
For example:
and in the ViewModel:
In this example, the ViewModel passes itself as a parameter to the view. The view can then check that the message is being sent from its view model.
我使用替代解决方案。 MyView 实现了一个包含 Close 方法的接口 IMyView。 MyViewModel 对象关联 View,因此它可以通过接口调用 Close 方法。
如果您对具体示例感兴趣,则可以查看:
WPF 应用程序框架 (WAF)
I use an alternative solution. MyView implements an interface IMyView which contains the Close method. The MyViewModel object associates the View and so it can call the Close method through the interface.
If you are interested in a concrete example then you might have a look at:
WPF Application Framework (WAF)