Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Splash Screen Windows

I need to have a PNG (with transparency) as a splash screen. The transparent portions of the image should be clear so the user can see any windows behind it (or desktop).

I also need to display the splash screen for 5 seconds (the contract specifically says 5 seconds) and it can't be any shorter. I am aware of the build property in VS 2010 but the splash screen comes and goes too quick (less than 5 seconds).

What can I do to make it stay 5 seconds (approximately)

like image 999
Cocoa Dev Avatar asked Jun 07 '11 17:06

Cocoa Dev


1 Answers

I had a similar problem, where i couldn't use the built-in splashscreen option, on a WPF project.

That project is now open source, you have have a look here: https://code.google.com/p/theomniscientchimp/

It's an auto-updater (there are a few things you don't need i guess).

This is the minimum you should need:

WPF side:

<Window x:Class="TheOmniscientChimp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:CustomXaml"
        Icon="SC2_Replay_Monkey.ico"
        Title="MainWindow" Height="256" Width="456" Background="#00005555" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" >
        <Grid Width="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />           
        </Grid.RowDefinitions>
        <Image Name="splashScreenImage" Stretch="Fill" Grid.Row="0" />
    </Grid>
</Window>

C# side (code behind):

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

            BitmapImage splashScreenImageSource = new BitmapImage();
            splashScreenImageSource.BeginInit();
            splashScreenImageSource.UriSource = new Uri("Your_Image.png", UriKind.Relative);
            splashScreenImageSource.EndInit();

            splashScreenImage.Source = splashScreenImageSource;
        }

        public void AsynchronousExit()
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync();
        }

        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Makes the thread wait for 5s before exiting.
            Thread.Sleep(5000);
        }

        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Environment.Exit(0);
        }
    }

Tell me if you need help to adjust.

FB.

like image 79
Louis Kottmann Avatar answered Oct 06 '22 01:10

Louis Kottmann