如何更改Silverlight加载屏幕背景?

时间:2010-10-01 03:55:36

标签: silverlight silverlight-4.0

我正在尝试避免在我的applet之前显示默认的Silverlight加载屏幕,并尝试显示空白的彩色背景,颜色与我的applet相同。目的是避免刺耳的白色,使它看起来像是一个应用程序绘图的所有部分。

我发现SplashScreenSource但我不知道如何将其连接起来只显示单一颜色背景而不是加载屏幕。有什么建议吗?

1 个答案:

答案 0 :(得分:5)

将新的XAML文件添加到ASP.NET网站,其中将显示Silverlight 用以下内容替换XAML的内容:

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

接下来,您需要在HTML条目页面或ASP.NET中添加JavaScript函数。

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

要使用此启动画面,您需要添加splashscreensource参数 识别您的XAML启动画面和onsourcedownloadprogresschanged参数 挂钩你的JavaScript事件处理程序。如果您想在下载完成时做出反应,那么您 可以使用onsourcedownloadcomplete连接不同的JavaScript事件处理程序 参数:

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

我希望这会对你有所帮助。