如何自定自己的 loading bar ?

dui_cky 2010-08-26 11:26:23
打开一个silverlight程序的时候默认的 是


如何修改设置成自己想要的效果 ? 如图


期待解答中 ~~~
...全文
97 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingjunli 2010-08-26
  • 打赏
  • 举报
回复
个人建议方案 通过动态加载的方式处理 参考:动态加载Silverlight应用的dll文件(可实现插件功能)

1、自已构件一个很小的主XAP就是显示一个加载条(这样很快闪过MS默认的进度条,显示自定义进度条);
2、通过后台动态加载主的XAP完成后再显示了来
  • 打赏
  • 举报
回复
前提条件,你的silverlight project要有一个website来host,创建sl应用程序时的默认选择.

1.创建你的加载页面。
在soulution explorer中的asp.net website中新加一个xaml页面,如DownloadingProgress.xaml,代码如下: 注意这里不支持Intellisense的,所以要认真写,这是我的布局,你可以适当调整,做出适合自己的。
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<StackPanel VerticalAlignment="Center">
<Canvas Width="400" Height="50">
<Rectangle x:Name="progressBarBackground" Fill="White" Stroke="Black" StrokeThickness="1" Height="30" Width="200" Canvas.Left="100" Canvas.Top="10"></Rectangle>
<Rectangle x:Name="progressBar" Fill="Yellow" Height="28" Width="0" Canvas.Left="101" Canvas.Top="11">
</Rectangle>
</Canvas>
<TextBlock x:Name="progressText" HorizontalAlignment="Center" Text="0% downloaded ..."></TextBlock>
</StackPanel>
</Grid>

2.在你的asp.net website中的***TestPage.aspx中加一段js脚本如下:
<script language="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-2);
}
</script>

3.在***TestPage.aspx中加参数,将加载页面和js脚本联系起来,如下:
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/ProgressBar.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="splashscreensource" value="DownloadingProgress.xaml" />
<param name="onsourcedownloadprogresschanged" value="onSourceDownloadProgressChanged" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>

这样就可以了。如有问题,再回贴问,先吃饭去了……
dui_cky 2010-08-26
  • 打赏
  • 举报
回复

感谢 MicrosoftCenterOfHN ,和 xingjunli 的回答 。 问题解决

MicrosoftCenterOfHN 的解决方案 运行效果如下


谢谢 ,xingjunli 提出的 建议方案 , 准备这样实现

8,756

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧