How do you change the Silverlight loading screen's background?
I'm trying to avoid the default Silverlight loading screen displaying before my applet and was trying to show a blank coloured background, the same colour as my applet's. The aim i开发者_开发百科s to avoid the jarring white and make it look like it's all part of one app drawing.
I've discovered SplashScreenSource but I'm not sure how to hook that up to just show a single colour background instead of the loading screen. Any suggestions?
Add new XAML file to ASP.NET website, in which Silverlight will be shown.
Replace content of XAML with this:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel VerticalAlignment="Center">
<Grid>
<Rectangle x:Name="progressBarBackground" Fill="White" Stroke="Black"
StrokeThickness="1" Height="30" Width="200"></Rectangle>
<Rectangle x:Name="progressBar" Fill="Yellow" Height="28" Width="0">
</Rectangle>
</Grid>
<TextBlock x:Name="progressText" HorizontalAlignment="Center"
Text="0% downloaded ..."></TextBlock>
</StackPanel>
</Grid>
Next, you need to add a JavaScript function to your HTML entry page or ASP.NET.
<script type="text/javascript">
function onSourceDownloadProgressChanged(sender, eventArgs)
{
sender.findName("progressText").Text =
Math.round((eventArgs.progress * 100)) + "% downloaded ...";
sender.findName("progressBar").Width =
eventArgs.progress * sender.findName("progressBarBackground").Width;
}
</script>
To use this splash screen, you need to add the splashscreensource parameter to identify your XAML splash screen and the onsourcedownloadprogresschanged parameter to hook up your JavaScript event handler. If you want to react when the download is finished, you can hook up a different JavaScript event handler using the onsourcedownloadcomplete parameter:
<object data="data:application/x-silverlight," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source" value="ClientBin/SplashScreen.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="splashscreensource" value="SplashScreen.xaml" />
<param name="onsourcedownloadprogresschanged"
value="onSourceDownloadProgressChanged" />
...
</object>
I hope this will help you.
精彩评论