隐藏 WPF 窗口直到完全加载

发布于 2024-08-06 08:42:07 字数 168 浏览 5 评论 0原文

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

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

疯到世界奔溃 2024-08-13 08:42:07

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

<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
}

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"
    />

And:

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
}
无人问我粥可暖 2024-08-13 08:42:07

您可以将窗口的 WindowState 设置为“最小化”,然后处理 ContentRendered 事件并将 WindowState 设置为“正常”或“最大化”。

You can set the windows WindowState to Minimized, then handle the ContentRendered event and set the WindowState to Normal or Maximized.

梦回旧景 2024-08-13 08:42:07

有一些函数,BeginInit 和 EndInit,如果您更改这些函数内的属性,例如......

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

那么您的窗口将不会呈现,直到调用 EndInit() 为止,它不会闪烁。

There are functions , BeginInit and EndInit, if you change properties inside these functions like..

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

then your window will not render until the EndInit() is called, it will not flicker.

送君千里 2024-08-13 08:42:07

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

When does this loading occur? Code executed in the main Window's constructor should execute before the window is shown; if you load any required resources there, you should not see any flickering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文