首页 新闻 会员 周边 捐助

SilverLight ProgressBar

0
悬赏园豆:100 [已解决问题] 解决于 2012-10-15 09:21

哪位大侠能提供一个完整的ProgressBar例子,页面加载时显示加载了百分之几,加载成功多少条,失败多少条?

AliceJin的主页 AliceJin | 初学一级 | 园豆:3
提问于:2012-10-11 16:37
< >
分享
最佳答案
0

 按如下步骤即可实现:

一、在承载SilverlightWeb网站目录下新建一个xaml页。命名为:SplashScreen.xaml。右击此属性,确保“生成操作”为“内容”。此页代码如下:

<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="parentCanvas"
>
<Grid x:Name="LayoutRoot">


<StackPanel Width="360" Grid.Row="1" Grid.Column="1" Height="236" VerticalAlignment="Top" Margin="0,150,0,0">
<Border BorderBrush="#FF5E849A" BorderThickness="1" Height="12" HorizontalAlignment="Center" VerticalAlignment="Center" Width="360" CornerRadius="5" Background="#FF0D283F" Grid.Row="3">
<!--显示进度条 SplanshScreen.js用到-->
<Grid x:Name="animaGrid" Margin="2" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5"/>
<ColumnDefinition/>
<ColumnDefinition Width="5"/>
</Grid.ColumnDefinitions>
<Border BorderThickness="0" CornerRadius="3,0,0,3">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FF70C7E8" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Border BorderThickness="0" Grid.Column="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FF70C7E8" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Border BorderThickness="0" CornerRadius="0,3,3,0" Grid.Column="2">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FF70C7E8" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</Border>
<!--显示百分比进度 SplanshScreen.js用到-->
<TextBlock x:Name="uxStatus"></TextBlock>
</StackPanel>
</Grid>
</Grid>

 

二、同样在此Web网站目录新建一个js文件,命名:SplanshScreen.js。js内容如下:

function onSourceDownloadProgressChanged(sender, eventArgs)
{
sender.findName("uxStatus").Text = "Loading: " + Math.round((eventArgs.progress * 1000)) / 10 + "%";
sender.findName("animaGrid").Width = eventArgs.progress * 354;
}

 

三、经过以上两个步骤后,最后只需在起始页中添加部分设置。如Login.aspx中。

1.在<head>...</head>中添加js文件引用:<script type="text/javascript" src="SplashScreen.js"></script>

2.在<object>....</object>中添加:

<param name="SplashScreenSource" value="SplashScreen.xaml"/>
<param name="OnSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" />

收获园豆:100
icyme | 初学一级 |园豆:77 | 2012-10-12 20:59
其他回答(2)
1

伪代码:

  

var i = 0;
foreach(var file in files)
{
    readfile(file);
    i++;
    progressBar1.value = progressBar1.max * (i / files.count); 
}
         

代码的意思也就是你在适当的地方设置一下progressbar的进度值就可以了。

空明流光 | 园豆:111 (初学一级) | 2012-10-11 17:05

能否给个实例看下额?

支持(0) 反对(0) AliceJin | 园豆:3 (初学一级) | 2012-10-12 14:54
1

同用沧海一杰的例子,readfile应该是一个长时间操作,请将循环放到另外一个线程异步执行,然后

用Dispatcher.BeginInvoke设置value,否则界面会卡住,然后看到progress直接跳到100

大佛脚下 | 园豆:416 (菜鸟二级) | 2012-10-11 21:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册