重用用户控件内的控件

发布于 2024-08-27 17:49:50 字数 152 浏览 7 评论 0原文

我有一个 UserControl UserControl1 和 UserControl1 内的一个按钮。我有一个 UserControl1ViewModel,它具有按钮的 ICommand 属性。使用此命令,我需要调用虚拟机外部(从其他虚拟机或主窗口的虚拟机)的方法。对此的最佳实践是什么?

I have a UserControl UserControl1 and a button inside the UserControl1. And I have a UserControl1ViewModel that has an ICommand property for the button. Using this command I need to call a method outside(from other VMs or VM of the MainWindow) the VM. What is the best practice for this?

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

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

发布评论

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

评论(3

秋心╮凉 2024-09-03 17:49:50

您可能想检查 Laurent Bugnion 的 MVVM lite http://www.galasoft.ch/mvvm/getstarted /

这是一个轻量级工具包,用于帮助实施 mvvm 概念。其中,每个视图模型都是 ViewModelLocator 类中的静态成员。例如,在你的命令中你可以做这样的事情。

ViewModelLocator.MainViewModel.MainContent = NewContent;

您完全可以在没有 mvvm lite 的情况下做到这一点,但使用它确实有助于加快学习曲线并加强模块化。

You might want to examine MVVM lite by Laurent Bugnion http://www.galasoft.ch/mvvm/getstarted/

This is a lightweight toolkit for helping enforce mvvm concepts. In it, every viewmodel is a static member in a ViewModelLocator class. So for instance, in your command you could do something like this.

ViewModelLocator.MainViewModel.MainContent = NewContent;

You can totally do this without mvvm lite, but using it really helps speed up the learning curve and enforce modularity.

不弃不离 2024-09-03 17:49:50

您很可能希望实现中介者模式来处理两个视图模型之间的通信。

另一个同样的问题是:
mvvm-view-model-view-model-communications

You're most likely looking to implement the Mediator pattern to handle the communication between two viewmodels.

Another SO question along the same vein is:
mvvm-view-model-view-model-communications

記憶穿過時間隧道 2024-09-03 17:49:50

我会考虑使用控制器在 ViewModel 之间进行中介。 WPF 应用程序框架 (WAF) 展示了其工作原理。

I would consider using Controllers for the mediation between the ViewModels. The WPF Application Framework (WAF) shows how this works.

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