How to Create a SplashScreen in WPF .Net 8

What is Splash Screen?

A splash screen is a graphical element that enhances the user experience during the initial loading process of software applications. It is typically shown while the application is initializing, loading resources, or performing setup tasks. A splash screen usually includes branding elements like a logo or name, as well as a progress indicator or loading message.

Advantages of using a splash screen

Here are several advantages of using a splash screen in a WPF application written in C#.

  1. Enhanced Professionalism: A well-designed splash screen can give your application a polished and professional appearance. It offers users a visually appealing introduction to your application while it loads, leaving a positive first impression.
  2. Branding and Marketing: Splash screens can reinforce your application's branding and identity. By prominently displaying your logo or brand name, you can increase brand recognition and awareness among users.
  3. User Feedback: Splash screens provide feedback to users that the application is loading and hasn't frozen or crashed. This helps manage user expectations and reduces frustration by indicating that the application is actively initializing.
  4. Loading Progress Indication: Splash screens often include loading indicators or progress bars, informing users about the progress of the application initialization process. This can help alleviate user impatience by giving them an idea of how much longer they need to wait.
  5. Preloading Resources: Splash screens can be used to preload essential resources or data required by the application, such as configuration settings, database connections, or application modules. This can help reduce perceived startup time when users interact with the application.
  6. Smooth Startup Experience: By displaying a splash screen during application initialization, you can create a smoother and more seamless startup experience for users. Even if the application takes some time to fully load, the splash screen provides a visual indication that the application is actively working.

To develop a splash screen in a WPF (Windows Presentation Foundation) application, one must design a distinct window that emerges upon application launch and remains visible for a brief duration before the primary window is displayed.

Implementation

Step 1. Create a Splash Screen Window like below.

<Window x:Class="WpfSplashScreenExample.SpalshScreen"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfSplashScreenExample"
        mc:Ignorable="d"
        Title="SpalshScreen" Height="450" Width="800" AllowsTransparency="True" WindowStyle="None" Background="Transparent" WindowStartupLocation="CenterScreen">

    <Grid>
        <!-- Add your splash screen content here -->
        <Image Source="/regularsplashscreen.png" />
    </Grid>
</Window>

Explanation of the properties used

  • WindowStyle="None": This removes the window border and title bar.
  • AllowsTransparency="True": This allows the window to have a transparent background.
  • Background="Transparent": This sets the background of the window to be transparent.
  • WindowStartupLocation="CenterScreen": This centers the window on the screen when it is launched.

Step 2. Set SplashScreen as Startup Window like below.

<Application x:Class="WpfSplashScreenExample.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfSplashScreenExample"
             StartupUri="SplashScreen.xaml">

    <Application.Resources>
        
    </Application.Resources>

</Application>

Step 3. Display the Main Window After Some Time.

using System.Threading;
using System.Windows;

namespace WpfSplashScreenExample
{
    /// <summary>
    /// Interaction logic for SpalshScreen.xaml
    /// </summary>
    public partial class SpalshScreen : Window
    {
        public SpalshScreen()
        {
            InitializeComponent();

            // Create a timer to close the splash screen after 10 seconds (adjust as needed)
            var timer = new Timer(TimerCallback, null, 10000, Timeout.Infinite);
        }

        private void TimerCallback(object state)
        {
            // Close the splash screen and show the main window
            Dispatcher.Invoke(() =>
            {
                var mainWindow = new MainWindow();
                mainWindow.Show();
                Close();
            });
        }
    }
}

Step 4. Design a primary interface for your application based on your specific needs.

<Window x:Class="WpfSplashScreenExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfSplashScreenExample"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" WindowState="Maximized">

    <Grid>
        <TextBlock Text="Welcome to Main Window" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>

</Window>

Step 5. Image of the Splash Screen.

Image of Splash Screen

Main Window

Note. The user has the ability to design a splash screen according to the specific requirements of the application.