WPF splash screen until windows ends loading

别来无恙 提交于 2019-12-05 18:19:27
Kent Boogaart

If you use the built-in SplashScreen class, you can call Show(false) to specify that you will be responsible for closing the splash screen. You can then use the Close() method to close it.

Note that the SplashScreen class only supports displaying a static image. It does this for very good reasons though - to get the splash screen up in front of your user as soon as possible.

Code would look something like this:

static class Entry
{
    static void Main(string[] args)
    {
        var splashScreen = new SplashScreen("path/to/your/image.png");
        splashScreen.Show(false);

        InitializeLogging();
        InitializeServices();
        InitializeUserInterface();
        InitializeWhateverElseYouNeed();

        splashScreen.Close(TimeSpan.FromSeconds(1));
    }
}

Dynamic splash screen (with progress updates etc.)

For the best results, you can use two-phase approach to SplashScreen:

Phase 1. Display static splash screen even before .NET code starts loading.

Static image loads using native code yet before .NET is initialized. Very effective to inform the user as soon as possible. There is a special way to achieve this.

Phase 2. Display custom form once .NET is loaded.

Design your custom form looking identically to your static splash screen when initially displayed. Showing the form will automatically fade-out static splash screen shown in Phase 1 (it is done by WPF) and since then you are free to display loading progress of your application. Hide this form (which can be always-on-top window) when your main window finishes loading its data.

If your splash screen is just an image - add the image to the project and set it's Build Action property to 'SplashScreen'. The framework will handle the rest. (VS2008 sp1 or later).

If you need the splash screen to differ (maybe displaying a version number) this approach wont work. If you want this take a look at the SplashScreen class that gives a little more flexibility.

May be because your data loading is complete but your UI thread have not finished rendering yet.Make sure that your UI is completely rendered before closing the splash.

Have a look the below links.

http://www.codeproject.com/KB/WPF/WPFsplashscreen.aspx

http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!