后台代码:

public partial class MainPage : PhoneApplicationPage
{
private long siz;
private long speed;
private Stopwatch sw;
private Stopwatch sw1; public MainPage()
{
InitializeComponent();
} private void button1_Click(object sender, RoutedEventArgs e)
{
testspeed();
} public void testspeed()
{
WebClient client = new WebClient();
progressBar1.Value = 0.0;
textBox2.Text = "0 %";
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(this.webClient_DownloadStringCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.webClient_DownloadProgressChanged);
sw = Stopwatch.StartNew();//用来记录总的下载时间
sw1 = Stopwatch.StartNew();//用来记录下载过程中的时间片,用于计算临时速度
client.DownloadStringAsync(new Uri("http://dl_dir.qq.com/qqfile/qq/QQ2011/QQ2011.exe"));
}
//下载过程事件
public void webClient_DownloadProgressChanged(object s, DownloadProgressChangedEventArgs 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 = this.speed + " KB/s";
progressBar1.Value = e.ProgressPercentage;
siz = e.TotalBytesToReceive;
textBlock3.Text = siz/1024/1024 + "MB";
sw1.Start();
}
//下载完成事件
public void webClient_DownloadStringCompleted(object s, DownloadStringCompletedEventArgs e)
{
sw.Stop();
siz = siz / 1024;
long num = siz / ((long)sw.Elapsed.Seconds);
sw.Reset();
textBox1.Text = "下载完成!";
textBlock1.Text = num + " KB/s";
}
}
}

XAML 设计代码:

<phone:PhoneApplicationPage
x:Class="DownLoad.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="WP7开发者" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="下载进度" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="114*"/>
<RowDefinition Height="493*"/>
</Grid.RowDefinitions>
<ProgressBar Foreground="Green" Height="30" HorizontalAlignment="Left" Margin="9,79,0,0" Name="progressBar1" VerticalAlignment="Top" Width="377" Value="0" Maximum="100" FontSize="72" BorderThickness="0"/>
<TextBlock Height="53" Margin="12,20,-16,0" Name="textBox1" Text="正在下载文件 . . ." VerticalAlignment="Top" Width="460"/>
<TextBlock Margin="6,24,287,427" Name="result" Text="下载的速度" Grid.Row="1"/>
<TextBlock Foreground="White" Height="59" HorizontalAlignment="Left" Margin="203,13,0,0" Name="textBox2" Text="" VerticalAlignment="Top" Width="123"/>
<Button Content="开始下载" Height="72" HorizontalAlignment="Left" Margin="96,244,0,0" Name="button1" VerticalAlignment="Top" Width="199" Click="button1_Click" Grid.Row="1"/>
<TextBlock Height="47" Margin="6,101,254,0" Name="finalresult" Text="平均的速度" VerticalAlignment="Top" Grid.Row="1"/>
<TextBlock Height="47" HorizontalAlignment="Left" Margin="132,89,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="156" Grid.Row="1"/>
<TextBlock Height="47" HorizontalAlignment="Left" Margin="6,166,0,0" Name="textBlock2" Text="文件的大小" VerticalAlignment="Top" Width="127" Grid.Row="1"/>
<TextBlock Height="47" HorizontalAlignment="Right" Margin="0,166,168,0" Name="textBlock3" Text="" VerticalAlignment="Top" Grid.Row="1" Width="156"/>
<TextBlock Height="47" HorizontalAlignment="Right" Margin="0,19,168,0" Name="textBlock4" Text="" VerticalAlignment="Top" Grid.Row="1" Width="156"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>

运行结果图:

    

Windows Phone 8 下载文件进度的更多相关文章

  1. C#获取windows 10的下载文件夹路径

    Windows没有为“下载”文件夹定义CSIDL,并且通过Environment.SpecialFolder枚举无法使用它. 但是,新的Vista 知名文件夹 API确实使用ID定义它FOLDERID ...

  2. 使用 new XMLHttpRequest() 制作下载文件进度条

    mui 进度控件使用方法: 检查当前容器(container控件)自身是否包含.mui-progressbar类: 当前容器包含.mui-progressbar类,则以当前容器为目标控件,直接显示进度 ...

  3. python实现socket上传下载文件-进度条显示

    在python的socket编程中,可以实现上传下载文件,并且在下载的时候,显示进度条,具体的流程如下图所示: 1. 服务器端代码如下: [root@python 519]# cat server.p ...

  4. 阿里云服务器(Windows)如何下载文件

    背景:公司只有我一个技术,在我之前还有一个老技术,属于兼职状态,为了尽快熟悉公司网站及app项目情况,我联系了老技术,请他尽快将代码发给我,他说代码文件过大,问我能不能连上服务器下载.百度了很多,都不 ...

  5. 使用tqdm实现下载文件进度条

    1.获取下载链接 下载链接为:http://fastsoft.onlinedown.net/down/Fcloudmusicsetup2.5.5.197764.exe 2.使用tqdm实现 2.1.从 ...

  6. linux上很方便的上传下载文件工具rz和sz使用介绍

    简单说就是,可以很方便地用这两个sz/rz工具,实现Linux下和Windows之间的文件传输(发送和接收),速度大概为10KB/s,适合中小文件.rz/sz 通过Zmodem协议传输数据   一般来 ...

  7. 在linux命令行利用SecureCRT上传下载文件

    一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地?与ssh有关的 ...

  8. C# Winform下载文件并显示进度条

    private void btnDown_Click(object sender, EventArgs e) { DownloadFile("http://localhost:1928/We ...

  9. WPF多线程下载文件,有进度条

    //打开对话框选择文件         private void OpenDialogBox_Click(object sender, RoutedEventArgs e)         {     ...

随机推荐

  1. IIS7配置PHP图解(转)

    IIS7+PHP_5.2.17 于之前安装IIS的时候已经选上了isapi扩展和isapi筛选,这里就不用另外再添加角色服务了,直接开始 先修改php.ini文件.. 把c:\php下的php.ini ...

  2. 数据分页处理系列之一:Oracle表数据分页检索SQL

      关于Oracle数据分页检索SQL语法,网络上比比皆是,花样繁多,本篇也是笔者本人在网络上搜寻的比较有代表性的语法,绝非本人原创,贴在这里,纯粹是为了让"数据分页专题系列"看起 ...

  3. python基础(四)运算

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python的运算符和其他语言类似 (我们暂时只了解这些运算符的基本用法,方便我们 ...

  4. mkfifo

    管道是Linux的十种文件类型之一,使用管道通信本质上还是以文件作为通信的媒介 有名管道+无名管道=管道 有名管道(FIFO文件):就是 有文件名的管道, 可以用于任意两个进程间的通信 无名管道(pi ...

  5. [转]C#网络编程(同步传输字符串) - Part.2

    本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part2.aspx 服务端客户端通信 在与服务端的连接建立以 ...

  6. MMORPG大型游戏设计与开发(客户端架构 part11 of vegine)

    从早年的无声电影到现在的逼真3D大片,人类在科技上可谓是一再突破.不知道有没有人经历过那无声的日子,没有声音的世界,咱们的耳朵也就失去了它本有的用途了.在游戏世界中,声音元素成了必不可少的一部分,一个 ...

  7. Java基础-super关键字与this关键字

    用super调用父类构造方法 类如果没有显式声明构造方法,则自动生成无参数的默认构造方法. 1.先用一个无参数的父类构造方法验证一下, 执行子类构造方法会自动调用父类的构造方法.测试代码: class ...

  8. Android蓝牙实例(和单片机蓝牙模块通信)

    最近做毕设,需要写一个简单的蓝牙APP进行交互,在网上也找了很多资料,终于给搞定了,这里分享一下^_^. 1.Android蓝牙编程 蓝牙3.0及以下版本编程需要使用UUID,UUID是通用唯一识别码 ...

  9. 网络之TCP/IP四层模型

    应用层(应用层.表示层.会话层):FTP.Telnet.DNS.SMTP 传输层(传输层):TCP<传输控制协议> . UDP<用户数据报文协议> 网际互连层(网络层):IP. ...

  10. Struts2 Action中动态方法调用、通配符的使用

    一.Struts2执行过程图: 二.struts2配置文件的加载顺序 struts-default.xml---struts-plugin.xml---struts.xml 具体步骤: 三.Actio ...