WPF Splash Screen Windows
Solution 1
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.
Solution 2
If i had to do it i would add a window and set its properties AllowsTransparency = true;
set it to start before all forms i mean before loading this can be done by modifying App.xml
and set Startup="Application_Startup
To disable the top defauld control you have to set WindowStyle = none
and there in its code
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow mn = new MainWindow();
mn.ShowDialog();
}
use timer to do what ever you want
private DispatcherTimer timer;
timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = TimeSpan.FromMilliseconds(5000);
timer.IsEnabled = true;
void timer_Tick(object sender, EventArgs e)
{
///Close your window here
}
hope this helps
Solution 3
I had the same problem, buts it's actually suprisingly easy to solve without anything special:
add your image in to the main project and set the build property to Splash Screen.
add a Thread.Sleep(5000) into the constructor for your app's main window right before the InitializeComponents() call.
This will delay the loading of your main wpf window, and the splash screen will stay up for at least the load time + the time of the sleep before the main window pops up and the splash goes away.

Cocoa Dev
Updated on June 12, 2022Comments
-
Cocoa Dev almost 2 years
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)
-
Cocoa Dev almost 13 yearsDoes this code go with the MailApplication or do I create a new WPF window and add the code(XAML/C#) to the new Window?
-
Louis Kottmann almost 13 yearsI made mine in a separate project, but you could put it in your main application, and call it before your application start.