WPF - Splash screen with status update

When your WPF application start up, there are times when it need to load some data or doing some long running task before your application window is fully loaded. So, splash screen is added to make it feel more responsive, but it is still not enough, some application may take a few task to run before loading the window. Most user will feel the application is hanging on splash screen and won't loads. So i thought adding a status update to the splash screen. Each completed task will update this status label.

This splash screen is actually a window control with windowstyle set to none and other properties set. You can add your splash image inside and set splash screen resolution to be the same with the image resolution. I posted the solution here.

To show the splash screen, you need to fire the event on startup. Then call Splash.BeginDisplay();.


App.xaml
<Application x:Class="SplashScreenWithStatus.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml" Startup="Application_Startup">
    <Application.Resources>
    </Application.Resources>
</Application>


App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
    Splash.BeginDisplay();
}


Then you need to call Splash.EndDisplay(); after you application's main window is loaded. I added Thread.Sleep(..); to simulate a long running task and update the status label accordingly when initializing component.

1 comments:

Anonymous said...

threading would make it even better

Post a Comment

top