David
David

Reputation: 25470

Adding a minimum display time for Silverlight splash screen

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).

Upvotes: 2

Views: 1481

Answers (2)

Scott Munro
Scott Munro

Reputation: 13596

Note that if you were only interested in extending the display time of the splash screen during development then it is very simple to add a Fiddler rule which delays the response off the Xap file.

This is an example of a rule that would have this effect. See Pedro Forte's post for details on how to apply the rule - it is really very easy!

if (oSession.uriContains("Midwinter.ReasonableBasis.Client.xap")){
    oSession["ui-color"]="orange"; 
    oSession["ui-bold"]="true";
    //Delay received data by X ms per KB downloaded.
    oSession["response-trickle-delay"] = "10"; 
}

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189505

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.

Upvotes: 2

Related Questions