2010-10-01 39 views
2

我试图避免在我的小应用程序之前显示默认的Silverlight加载屏幕,并试图显示一个空白的彩色背景,与我的小应用程序的颜色相同。其目的是避免令人不安的白色,并使其看起来像它是一个应用程序绘图的一部分。如何更改Silverlight加载屏幕的背景?

我发现了SplashScreenSource,但我不确定如何挂钩以显示单一颜色背景而不是加载屏幕。有什么建议么?

+0

我实际上设法使用http://msdn.microsoft.com/en-us/library/cc838130(v=vs.95).aspx有时显示图像,但似乎到时候假加载屏幕已加载,所以我的小程序。那么有什么办法可以完全避免白屏? – dlanod 2010-10-01 04:09:44

回答

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> 

接下来,你需要一个JavaScript函数添加到您的HTML登录页面或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> 

要使用此启动画面,您需要将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> 

我希望这会帮助你。

+0

我没有使用ASP.NET网站,但是XAML可以存在于单独的文件中并且具有相同的效果? – dlanod 2010-10-05 05:34:21

+0

我认为是的,它必须在单独的文件中,而其他部分必须放置在Silverlight应用程序所在的页面(可能是html文件或其他文件) – 2010-10-05 06:36:06