Search code examples
wpfsplash-screen

WPF Disable Splash Screen Programmatically


I have a WPF application that optionally accepts command line parameters. One of these parameters specifies "silent mode" (no UI). How can I disable the presentation of the splash screen at startup based on this parameter?


Solution

  • You should explicitly create an instance of the class SplashScreen, and show/hide based on your program arguments, instead of using the SplashScreen build action to generate a splash screen.

    You need to set the Build Action of your splash screen image to Resource instead of SplashScreen.

    For Example:

    private void OnStartUp(Object sender, StartupEventArgs e)
    {
    
        if (ShowSplashScreenArgument)
        {
            SplashScreen splashScreen = new SplashScreen("YourSplashScreen.bmp");
            splashScreen.Show();
        }
    
        // Do loading code here..
    
        MainWindow mainWindow = new MainWindow();
    
        if (ShowSplashScreenArgument)
        {
            // Close the splash..
            splashScreen.Close();
        }
    
        mainWindow.Show();
    }