隐藏WPF窗口直到完全加载

对于我的WPF应用程序,我存储了几个用户设置,如窗口位置,窗口状态,以及是否显示欢迎对话框。 问题是,当所有内容都加载时,我会看到很多闪烁和闪烁,因为窗口被加载,然后在读取设置后窗口最大化时更多闪烁。

我已经在使用内置的WPF PNG启动画面function,但有没有办法完全隐藏所有窗口的渲染,直到所有内容都完全加载?

编辑Application.xaml,删除StartUpUri,而不是设置StartUp事件处理程序。 在Application.xaml.cs中,编辑启动事件处理程序以显示启动画面,加载资源,创建所有内容,然后创建主窗口并显示它。

 

和:

 private void OnStartUp(Object sender, StartupEventArgs e) { var settings = LoadSettingsFrom... // Call your implementation of load user settings // Example only, in real app do this if's section on a different thread if (settings.doShowSplashScreen) { var splashScreen = new SplashScreen(); splashScreen.Show(); } // Load and create stuff (resources, databases, main classes, ...) var mainWindow = new mainWindow(); mainWindow.ApplySettings(settings); // Call your implementation of apply settings if (doShowSplashScreen) { // send close signal to splash screen's thread } mainWindow.Show(); // Show the main window } 

有一些函数,BeginInit和EndInit,如果你改变这些函数里面的属性,比如..

 BeginInit(); ... ... // Do your code Initialization here... ... EndInit(); 

然后你的窗口将不会渲染,直到调用EndInit(),它不会闪烁。

您可以将Windows WindowState设置为Minimized,然后处理ContentRendered事件并将WindowState设置为Normal或Maximized。

这种加载何时发生? 在主Window的构造函数中执行的代码应该在窗口显示之前执行; 如果你在那里加载任何所需的资源,你不应该看到任何闪烁。