隐藏WPF窗口,直到完全加载 [英] Hide WPF Window Until Fully Loaded

查看:362
本文介绍了隐藏WPF窗口,直到完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For my WPF application, I am storing several user settings like window position, window state, and whether or not to display a welcome dialog. The problem is that while everything is loading up, I see a lot of flashing and flickering as the windows are loaded in, and then more flickering when the window is maximized after reading in the settings.

我已经在使用内置的WPF PNG初始屏幕功能,但是有没有一种方法可以完全隐藏所有窗口的渲染,直到全部加载完毕?

I am already using the built-in WPF PNG splash screen functionality, but is there a way to completely hide the rendering of all windows until everything is fully loaded in?

推荐答案

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

Edit the Application.xaml, remove the StartUpUri, instead set the StartUp event handler. In Application.xaml.cs, edit the startup event handler to display the splashscreen, load your resources, create everything, then create the main window and show it.

<Application
    ...
    StartUp="OnStartUp"
    />

并且:

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
}

这篇关于隐藏WPF窗口,直到完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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