【问题标题】:How do you change the Silverlight loading screen's background?如何更改 Silverlight 加载屏幕的背景?
【发布时间】:2010-10-01 03:55:35
【问题描述】:

我试图避免在我的小程序之前显示默认的 Silverlight 加载屏幕,并试图显示一个空白的彩色背景,与我的小程序的颜色相同。目的是避免不和谐的白色,让它看起来像是一个应用程序绘图的一部分。

我发现了SplashScreenSource,但我不确定如何将其连接起来以仅显示单色背景而不是加载屏幕。有什么建议吗?

【问题讨论】:

标签: silverlight silverlight-4.0


【解决方案1】:

将新的 XAML 文件添加到将显示 Silverlight 的 ASP.NET 网站。
将 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>   

希望对你有帮助。

【讨论】:

  • 我没有使用 ASP.NET 网站,但 XAML 是否可以仅存在于单独的文件中并具有相同的效果?
  • 我认为是的,它必须在单独的文件中,其他部分必须在您的silverlight应用程序所在的页面中(可能是html文件或其他文件)
猜你喜欢
  • 1970-01-01
  • 2021-12-29
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
  • 2011-05-17
相关资源
最近更新 更多