6

I try to implement Splash Screnn in WPF. I have found some nice ehample in MSDN, but there is one place:

private void _applicationInitialize(SplashScreen splashWindow)
{

    Thread.Sleep(1000);

    // Create the main window, but on the UI thread.

    Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate
    {

        Window1 MainWindow = new Window1();

        Helper.setWin(MainWindow);

        MainWindow.Show();

    });

}

The problem is Helper, whats the class is there and how it must be implemented. Someone could paste an example or smth?

Vytas
  • 1,271
  • 4
  • 18
  • 26

2 Answers2

12

There is an even easier way:

http://msdn.microsoft.com/en-us/library/cc656886.aspx

  1. Add the image file to the WPF Application project. For more information, see How to: Add Existing Items to a Project.
  2. In Solution Explorer, select the image.
  3. In the Properties window, click the drop-down arrow for the Build Action property.
  4. Select SplashScreen from the drop-down list
Guy
  • 3,353
  • 24
  • 28
6

You can use code like this do display an image on startup:

<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml" Startup="Application_Startup">

in the code behind:

private void Application_Startup(object sender, StartupEventArgs e)
{
    SplashScreen screen = new SplashScreen("Images/splash.bmp");
    screen.Show(true);
}
Guy
  • 3,353
  • 24
  • 28
  • 3
    Yuor example shows a splash screen and leaves it open. Actually splash screen must be shown before mainWindow and it must close itself automaticaly before MainWindow appears. – Vytas Nov 16 '09 at 13:08
  • 2
    The boolean value on the show method is named autoclose. This allows WPF to automatically handle closing the splash screen on the main window load event. – Guy Nov 16 '09 at 13:39
  • Maybe yuo can paste yuor splash screen window code? That wuold be easier to understand. – Vytas Nov 16 '09 at 15:28
  • 1
    It is a standard wpf class: System.Windows.SplashScreen – Guy Nov 16 '09 at 16:43
  • I dont reference the splashscreen anywhere else in the code, this is literally all there is to it. – Guy Nov 16 '09 at 16:44