Skip Navigation LinksHome > View Post

Showing a Splash Screen whilst initializing a WPF Prism application

I hosted an internal session on Patterns & Practices Prism (or Composite Application Guidance) and one of the attendees asked if there was a way I could avoid showing the application’s shell in its unpopulated state whilst the Modules load.

There are a number of ways of doing this but I thought I’d share the approach I use in one of my applications.

Now, there’s obviously going to be some delay to your app whilst Prism loads your modules, or you wouldn’t be here, and we don’t want to risk the user trying to start multiple instances of the application or wondering what’s going on – so let’s show a Splash screen.

I chose to implement the splash screen inside my Prism bootstrapper where I create the Shell. Here’s the typical code

public override DependencyObject CreateShell()
{
    Shell shell = new Shell();
    shell.Show();
    return shell;
}

And here’s what I’d change to introduce a splash screen (e.g. SplashScreen.xaml) that closes when Prism is done loading modules:

public override DependencyObject CreateShell()
{
    SplashScreen splash = new SplashScreen();
    splash.Show();
    Shell shell = new Shell();
    shell.Dispatcher.BeginInvoke((Action) delegate
        {
            shell.Show();
            splash.Close();
        });
    return shell;
}

This takes advantage of the fact that the Bootstrapper and ModuleLoader run on the UI thread and queues a delegate on the Dispatcher that will only get invoked when all the other stuff is done.

Tags: Prism WPF

 
Josh Post By Josh Twist
9:49 AM
12 Jan 2009

» Next Post: WPF Snippets for Visual Studio
« Previous Post: Things I love about Windows 7 (beta)

Comments are closed for this post.

Posted by Tere @ 09 Apr 2010 8:46 AM
I used a ShellPage (Page) and it not contain method "Show", please how to implement a splash screen for this case.

© 2005 - 2014 Josh Twist - All Rights Reserved.