views:

244

answers:

1

When hosting a silverlight application on a webpage it is possible to use the splashscreensource parameter to specify a simple Silverlight 1.0 (xaml+javascript) control to be displayed while the real xap file is downloaded, and which can receive notification of the downloads progress through onSourceDownloadProgressChanged. If the xap file is in cache, the splash screen is not shown (and if the download only takes 1 second, the splash screen will only be shown for 1 second).

I know this is not best practice in general, but I am looking for a way to specify a minimum display time for the splash screen - even if the xap cached or the download is fast, the splash screen would remain up for at least, let's say, 5 seconds (for example to show a required legal disclaimer, corporate identity mark or other bug).

  • I do want to do it in the splash screen exclusively (rather then in the main xap) as I want it to be clean and uninterupted (for example a sound bug) and shown to the user as soon as they open the page, rather then after the download (which could take anywhere from 1 to 20+ seconds).

  • I'd prefer not to accomplish this with preloading - replacing the splash screen with a full Silverlight xap application (with it's own loading screen), which then programmably loads and displays the full xap after a minimum wait time.

+1  A: 

Its a little known fact that the splash screen remains in place beyond the time that XAP takes to load. It doesn't get replaced until the application RootVisual loads. Hence if you don't assign the RootVisual in the application Startup event the splash screen displays forever.

Hence you can delay the display of the splash for a few seconds using code like this:-

private void Application_Startup(object sender, StartupEventArgs e)
{
    var timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromSeconds(10);
    EventHandler eh = null;

    eh = (s, args) =>
    {
        timer.Stop();
        this.RootVisual = new Test();
        timer.Tick -= eh;
    };

    timer.Tick += eh;

    timer.Start();
}

This can be simplified with the Reactive framework:-

private void Application_Startup(object sender, StartupEventArgs e)
{
    Observable.Timer(TimeSpan.FromSeconds(10), Scheduler.Dispatcher)
        .Subscribe((l) =>
    {
        this.RootVisual = new Test();
    });
}

However the Reactive framework adds at least 66KB to the size of your Xap so only use it you are already using the Reactive stuff for other things.

AnthonyWJones
I'll have to check if it's possible for both to be interacting with Javascript. If that's the case I can see the splash screen setting a "done" flag in Javascript when it's ready to be closed, and the application startup checking for that flag every 250ms until it is set or some timeout is reached.
David
@David: Let us know how that check works out, I'd be curious also as to whether the application can access the javascript whilst the splash screen is still in effect.
AnthonyWJones