<param name="SplashScreenSource" value="SplashScreen.xaml"/>
<param name="OnSourceDownloadProgressChanged" value="OnSourceDownloadProgressChanged" />
<param name="source" value="ClientBin/SilverLightAppTest.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
在SilverLight加载时Object标签中新加入两个参数:
1.SplashScreenSource属性用于标记初始屏幕xaml页
2.OnSourceDownloadProgressChanged属性用于加载进度变化时的事件处理程序
程序如下:
SplashScreenSource.xaml:
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel HorizontalAlignment="Center">
<Grid HorizontalAlignment="Center">
<Rectangle Stroke="#FFDEE6F0" HorizontalAlignment="Left" Width="300"
Height="10" RadiusX="2" RadiusY="2" StrokeThickness="1"/>
<Rectangle Fill="#FF7E99C8" HorizontalAlignment="Left" VerticalAlignment="Center"
StrokeThickness="0" RadiusX="0" RadiusY="0" Width="296" Height="6" x:Name="progressBar"
RenderTransformOrigin="0,0.5" Margin="4">
<Rectangle.RenderTransform>
<ScaleTransform x:Name="progressBarScale" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
<Grid HorizontalAlignment="Center">
<TextBlock x:Name="progressText" Margin="18,0,17,19" Height="26" Text="0%"
FontSize="16" Opacity="0.8" VerticalAlignment="Bottom" TextAlignment="Right"/>
<TextBlock x:Name="progressText2" Margin="18,0,7,8" Height="70" Text="0%"
FontSize="50" Opacity="0.04" FontWeight="Bold" VerticalAlignment="Bottom" TextAlignment="Right"/>
</Grid>
</StackPanel>
</Grid>
OnSourceDownloadProgressChanged
function OnSourceDownloadProgressChanged(sender, args) {
sender.findName("progressText").Text = Math.round(eventArgs.progress * 100) + "%";
sender.findName("progressText2").Text = Math.round(eventArgs.progress * 100) + "%";
sender.findName("progressBarScale").ScaleX = eventArgs.progress;
}
这样就自定义了一个非托管代码的初始化进度条显示.