获取查看&放大器;视图模型从插件 [英] Get the View & ViewModel from a plugin

查看:226
本文介绍了获取查看&放大器;视图模型从插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用插件的应用程序。每个插件developped以下MVVM,所以我有一个观点,绑定到一个视图模型内。像下面的图片:

I have an application which use plugins. Each plugin is developped following MVVM, so I have a View, binded to a View-Model inside. like the following picture:

在我的应用程序有一个设计师,我在我的ViewModels列表中添加任何视图模型,视图将出现在Designer中。

In my application I have a Designer, when I add any ViewModel in my ViewModels list, its view will appear in the Designer.

我的问题是:我怎样才能保持这在我的列表中添加我的插件的视图模型时,结合?如何将它的观点出现在我的设计师?

推荐答案

这是一个有趣的问题...并像往常一样有很多种方法来完成它。

This is an interesting question... and like always there are many ways to accomplish it.

这要看你的插件是什么。

It depends what your plugins are.

如果该插件是更加一体化,而不是如此孤立。你应该想想这是例如命名为喜欢的的ViewResolver ViewModelResolver 工厂班code>。他们可以像名称作为字符串参数 A型,一个接口的类型或约定的工作。

If the plugin is more integrated and not so isolated. You should think about some Factory classes which are for example named like ViewResolver or ViewModelResolver. They can take parameters like the name as string, a type, a type of an interface or work by conventions.

目的是找到虚拟机的视图,反之亦然为中心的服务。该服务也应该找到插件VM或导入例如使用MEF。

Purpose is to find the VM for a view and vice versa as a central service. This service should also locate plugin VM or import them for example with MEF.

有关更多信息的谷歌的看法,第一,视图模型为先,查看视图模型婚姻等

For more info’s google on view-first, viewmodel-first, view viewmodel marriage, etc.

如果您的插件是完全充实它独立运行的组件。我建议你的主机应用程序应该在其视图模型这是插件组件列表。因此,该模型将组件不管它包含视图和其他一切因托管应用程序是管理组件。所以,你会拥有这必将对内容控制一个ObservableCollection。该内容控制就可以承载插件作为一个整体。

If your plugins are fully fleshed out components which run independently. I would suggest your host application should have in its viewmodel a list of components which are the plugins. So the Model will be a Component no matter if it contains the view and everything else because of the hosting app is to manage the components. So you would have an ObservableCollection which are bound to content control. The content control can then host the plugin as a whole.

这是两种可能的方式...就像我上面提到没有的方式MVVM它总是取决于你的使用案例...
,但我希望这将引导你在正确的方向...

These are two possible ways... like I mentioned above there is no "the" way in mvvm and it always depends on your use cases... But I hope this guides you in the right direction...

心连心

这篇关于获取查看&放大器;视图模型从插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆