如何在应用程序启动时预加载棱镜视图?
我们将 Prism 4用于WPF 以及Prism随附的导航功能.
We use Prism 4 for WPF as well as the navigation functionality which comes with Prism.
导航到(加载)我们应用程序中的某些视图时,我们会注意到一个延迟-可以理解地来自实例化视图及其依赖关系,这包括从磁盘加载必要的程序集.
When navigating to (loading) certain views in our application we notice a delay - which understandably comes from instantiating the view and its dependencies, this includes loading necessary assemblies from disk.
我们希望在应用程序启动时预加载这些视图,同时显示初始屏幕或类似内容.
We would like to preload these views at application startup while showing a splash screen or something similar.
有人做过类似的事情并想分享他们的经验吗?
Has anyone done something similar and would like to share their experiences?
我们还没有找到一种干净"的解决方案.但这就是我们解决的方式.
We haven't found a "clean" solution to do this yet. But this is how we have solved it.
在引导程序函数InitializeShell()中,我们导航到要预加载的所有视图.最后,我们导航到要在主屏幕中显示的所有视图.
In the bootstrapper function InitializeShell() we navigate to all views we want to preload. As last we navigate to all the views we want to show in our homescreen.
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (MainShell) Shell;
// Preload views
// ---- Load (navigate to) all views here you want to have preloaded
// Load actual default views
// ---- Load (navigate to) the actual views for your "homescreen"
// Finished loading now show the shell
Application.Current.MainWindow.Show();
}
这不是理想的情况,如果您有很多意见,可以进行大量维护工作.这为我完成了工作,但是如果有人有更好的解决方案,我也很感兴趣.
It's not an ideal situation and can give lots of maintenance work if you have a lot of views. This does the job for me, but I'm also interested if anyone has a betters solution.