Silverlight PRISM创建自定义模块目录 [英] Silverlight PRISM Creating a custom module catalog

查看:76
本文介绍了Silverlight PRISM创建自定义模块目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用PRISM和MEF创建了silverlight应用程序. 有没有一种方法可以通过某些Web服务或数据库调用来填充模块目录? PRISM文档中显示的示例通过Shell项目中包含的XAP文件获取模块信息. 就我而言,我需要从某些服务中获取此列表.我读了一些建议创建一个实现IModuleCatalog的自定义ModuleCatalog的文章.

I have created a silverlight application with PRISM and MEF. Is there a way to populate the modules catalog through some web service or database call? The example shown in the PRISM documentation gets the module information through XAP file which is included in the Shell project. In my case i need to get this list from some service. I read some articles which suggested to create a custom ModuleCatalog which implements IModuleCatalog.

我找不到任何有关如何进行操作的示例或代码段. 有关如何实现此目标的任何建议?

I am not able to find any example or code snippet on how to proceed. Any suggestions on how to accomplish this?

谢谢, 迪帕克

推荐答案

为此要求提供了解决方案. 为了在运行时加载OnDemand模块,必须将Module Info对象添加到目录中

Got the solution for this requirement. Inorder to do load the OnDemand Module in runtime, the Module Info object has to be added into the catalog

            ModuleInfo moduleInfo = new ModuleInfo();
            moduleInfo.ModuleName = item.Name;
            moduleInfo.ModuleType = item.Type;
            moduleInfo.Ref = item.Reference;
            ModuleCatalog.AddModule(moduleInfo);

上面的代码中显示的项目是使用webservice调用填充的,该调用会打入数据库并获取名称,类型和引用(example.xap).

The item shown in the above code is populate using a webservice call, which hits the database and gets the name, type and reference (example.xap).

这成功添加了模块目录,只需导入该属性即可在任何ViewModel中引用该模块目录,如下所示

This successfully adds the module catalog, the module catalog can be referenced in any ViewModel by just importing that property like below

    [Import(AllowRecomposition = false)]
    public IModuleManager ModuleManager;

    [Import(AllowRecomposition = false)]
    public IModuleCatalog ModuleCatalog;

为了在单击按钮或发生任何事件期间加载模块,只需调用ModuleManager.LoadModule(YourModuleName);.就是这样,它将可以使用.

Inorder to Load the module during a button click or any event just call the ModuleManager.LoadModule(YourModuleName); and thats it, it will be available for use.

这篇关于Silverlight PRISM创建自定义模块目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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