Add minimum display time for the Silverlight splash screen
When hosting a Silverlight application on a web page, you can use an option splashscreensource
to specify a simple Silverlight 1.0 (xaml + javascript) control to display when the actual xap file is loaded, and which can be notified of the progress of the download via onSourceDownloadProgressChanged
. If the xap file is in the cache, no splash screen is displayed (and if the download takes only 1 second, the splash screen will only show for 1 second).
I know this is not best practice in general, but I am looking for a way to specify the minimum display time for the splash screen - even if the xap caching or loading is fast, the splash screen will stay for at least, say 5 seconds (for example, to show the required legal refusal, corporate identity mark or other error).
-
I only want to do this in the popup screen (not the main xap) as I want it to be clean and uninteresting (like a sound error) and shown to the user as soon as they open the page, not after loading (which may take 1 to 20 seconds).
-
I'd rather not do this pre-loaded - replacing the splash screen with a full Silverlight xap application (with its own loading screen), which is then programmed and displays the full xap after a minimal timeout.
a source to share
Its a little known fact that the splash screen stays in place in the time it takes XAP to load. It is not replaced until the application is loaded RootVisual
. Hence, if you don't assign RootVisual
in the app Startup
, the splash screen will be displayed forever.
Hence, you can delay the display of the splash by a few seconds using the following code: -
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 use it, you are already using Reactive for other things.
a source to share
Note that if you were only interested in extending the splash screen time during development, then it's very easy to add a Fiddler rule that delays the response from the Xap file.
This is an example of a rule that will have this effect. See Pedro Forte's post for details on how to apply the rule - it's really 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";
}
a source to share