鸿 网 互 联 www.68idc.cn

Windows Phone 8 下载文件进度

来源:互联网 作者:佚名 时间:2013-12-23 15:43
后台代码: PhoneApplicationPage { private long siz; private long speed; private Stopwatch sw; private Stopwatch sw1; public MainPage(){InitializeComponent();} e){testspeed();} public void testspeed(){ ();progressBar1.Value = 0.0;textBox2.Te

后台代码:

PhoneApplicationPage { private long siz; private long speed; private Stopwatch sw; private Stopwatch sw1; public MainPage() { InitializeComponent(); } e) { testspeed(); } public void testspeed() { (); progressBar1.Value = 0.0; textBox2.Text = "0 %"; client.DownloadStringCompleted += .webClient_DownloadStringCompleted); client.DownloadProgressChanged += .webClient_DownloadProgressChanged); sw = Stopwatch.StartNew();//用来记录总的下载时间 //用来记录下载过程中的时间片,,用于计算临时速度 )); } //下载过程事件 e) { textBox2.Text = e.ProgressPercentage.ToString() + " %"; sw1.Stop(); long num = e.BytesReceived / 1024; if (sw1.Elapsed.Seconds != 0) { speed = num / ((long)sw1.Elapsed.Seconds); } textBlock4.Text = ; progressBar1.Value = e.ProgressPercentage; siz = e.TotalBytesToReceive; textBlock3.Text = siz/1024/1024 + "MB"; sw1.Start(); } //下载完成事件 e) { sw.Stop(); siz = siz / 1024; )sw.Elapsed.Seconds); sw.Reset(); textBox1.Text = "下载完成!"; textBlock1.Text = num + " KB/s"; } } }

XAML 设计代码:

PhoneApplicationPage ="DownLoad.MainPage" xmlns="" ="" ="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" ="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" ="" ="" ="768" }" }" }" ="Portrait" ="True"> <="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <="12,17,0,28"> <}"/> <}"/> </StackPanel> <="12,0,12,0"> <Grid.RowDefinitions> <RowDefinition Height="114*"/> <RowDefinition Height="493*"/> </Grid.RowDefinitions> <="0"/> <="460"/> <="1"/> <="123"/> <="1"/> <="1"/> <="1"/> <="1"/> <="156"/> <="156"/> </Grid> </Grid> </

运行结果图:

image

    

image

网友评论
<