Silverlight Prism模块尚未就绪 [英] Silverlight Prism Module Not Ready

查看:105
本文介绍了Silverlight Prism模块尚未就绪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Prism(也称为复合应用程序指南)构建Silverlight 4.0应用程序。我有两个模块,都在我的 ModuleCatalog.xaml 中定义为 WhenAvailable 。我的Application_OnStart实例化我的 Bootstrapper 并调用它的 Run()方法。在我的应用程序启动并启动并运行之后(实际上,用户必须单击UI中的按钮),然后我尝试加载模块:

I'm building a Silverlight 4.0 application with Prism (a.k.a. Composite Application Guidance). I have two modules, both defined in my ModuleCatalog.xaml as WhenAvailable. My Application_OnStart instantiates my Bootstrapper and invokes it's Run() method. Well after my application is started and up and running (in fact, the user has to click a button in the UI), I then attempt to load the modules:

foreach (ModuleInfo mi in moduleCatalog.Modules)
    ...
    Type moduleType = Type.GetType(mi.ModuleType); // moduleType ends up null!

有时, moduleType 最终为空。我已经验证,当我遇到null时,ModuleInfo的 State LoadingTypes 而不是 ReadyForInitialization 。我认为这意味着它仍在为模块下载单独的* .xap文件并将其类型引入应用程序域。

Sometimes, moduleType ends up null. I've verified that when I encounter the null, the ModuleInfo's State is LoadingTypes not ReadyForInitialization. I assume this means it's still downloading the separate *.xap files for my modules and bringing their types into the application domain.

那我该怎么办?如果我知道有些事件我可以听完以至于知道它们终于全部加载完毕,我会很高兴地阻止。

So what can I do? I'd happily block if I knew there was some event I could listen to to know they're finally all loaded.

推荐答案

如果要使用Prism,则不要绕过它并自己创建模块。这不是Prism应该工作的方式。 Prism不提供加载完成事件,因为这不是您应该要做的事情。

If you are going to use Prism, you should not bypass it and create your modules yourself. That is not the way Prism is supposed to work. Prism does not provide an event for load completion as that is not something you should need to do.

如果定义模块目录,则所有那些模块都将逐步加载,因此在这种简单情况下无需手动加载任何模块。您可以在根Silverlight应用程序中创建一个具有一些模块依赖性的启动模块,这足以使第一页可见,而其余的应用程序加载。

If you define a module catalogue then all those modules will be loaded progressively, so no need to load any manually in that simple case. You can create a start-up module in your root Silverlight app with a few module dependencies and that will be enough to get the first page visible while to rest of the app loads.

我无法从上述代码段中得知您实际要完成的工作,因此更多信息会有所帮助,但您应该使用Unity解决接口,决不要直接使用Type.GetType()。通常,您通常不需要解析模块本身,在Prism中也有一些方法可以触发按需加载(暂时不用它们……将对其进行更新)。

I can't tell what you are actually trying to accomplish from the above snippet, so more information would help, but you should be using Unity to resolve interfaces and never Type.GetType() directly. Your generally should not need to resolve a module itself and there are also methods for triggering load-on-demand loading in Prism (don't have them handy at the moment... will update this).

您不小心提供了我在Stack Overflow中问过的另一个问题,因此感谢

Your have accidentally provided a clue to the answer to another question I asked in Stack Overflow so thanks for that.

这篇关于Silverlight Prism模块尚未就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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