简体   繁体   English

在WPF / PRISM中重新初始化应用程序

[英]Re-initializing application in WPF / PRISM

We are building a WPF application using PRISM and MEF. 我们正在使用PRISM和MEF构建WPF应用程序。 In the application, the user will start out by browsing to a 'project file' which contains a large amount of meta data. 在应用程序中,用户将通过浏览到包含大量元数据的“项目文件”来开始。

Based on the project meta data, a set of views and their dependent viewmodels will be created and the user can view / create / manipulate the project data. 基于项目元数据,将创建一组视图及其相关的视图模型,并且用户可以查看/创建/操作项目数据。

The user can then go to open another project file, which should at that point completely re-initialize the application as if the user had restarted the application and this was the first project file being opened. 然后,用户可以打开另一个项目文件,这时应完全重新初始化应用程序,就像用户已经重新启动应用程序一样,这是第一个打开的项目文件。 The reason for this is that different project files could result in very different views being created. 原因是不同的项目文件可能会导致创建非常不同的视图。

How can this be done in WPF / PRISM / MEF? 如何在WPF / PRISM / MEF中完成此操作? If it was a regular WinForms application we could deconstruct / tear down the base 'application form' if you will and start over by instantiating a new one, using the project meta data as the context. 如果它是常规的WinForms应用程序,那么您可以使用项目元数据作为上下文,通过实例化一个新的窗体来解构/拆除基本的“应用程序窗体”。

Is there a way to do something similar in WPF/ PRISM / MEF? 有没有办法在WPF / PRISM / MEF中做类似的事情? The behavior between different types of projects and the initialization required is too complex for the 'oh, just swap out the model and have the viewmodels fire property change events for the views to refresh themselves' approach. 不同类型的项目之间的行为以及所需的初始化对于“哦,只需换掉模型并让viewmodels触发属性更改事件以使视图刷新自己”的方法就太复杂了。

How about you instantiate a new Bootstrapper over the current one and re-run it, in your Application OnStartUp ? 在应用程序OnStartUp中,如何在当前实例上实例化一个新的Bootstrapper并重新运行它? I tested it and it seems to work, but would that be enough in your case ? 我对其进行了测试,它似乎可以正常工作,但是在您的情况下就足够了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM