views:

553

answers:

2

Hello, 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?

+4  A: 

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
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
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
Maybe yuo can paste yuor splash screen window code? That wuold be easier to understand.
Vytas
It is a standard wpf class: System.Windows.SplashScreen
Guy
I dont reference the splashscreen anywhere else in the code, this is literally all there is to it.
Guy
+4  A: 

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
You're missing the last step: 4. Select SplashScreen from the drop-down list.
Ray Burns
good spot, my bad
Guy
This answer is very good, espiacially for the beginners. Thankfull.
Vytas