downloader对象为Silverlight 插件提供了下载功能,其通过HTTP(get)请求异步下载指定的内容.
downloader所支持的event包括:
Completed:下载完成 (Downloader)
DownloadFailed: 下载失败
DownloadProgressChanged:下载进度变化 (Downloader)
支持的方法包括:
Abort, Equals, FindName (DependencyObject), GetHost, GetResponseText, GetValue, Open,
Send, SetValue
下面这个DEMO演示使用downloader从网上下载jpg图片以及xaml文件并完成数据加载的过程:
其xaml代码如下所示:
<Canvas Canvas.Left="10">
<TextBlock Canvas.Left="10" Canvas.Top="5" Name="StartDownLoadImg">下载图片</TextBlock>
<TextBlock Canvas.Left="150" Canvas.Top="5" Name="StartDownLoadXaml">下载xaml</TextBlock>
</Canvas>
<!-- 下载进度条 -->
<Canvas Canvas.Top="40">
<Rectangle Name="progressRectangle" Canvas.Left="20" Height="10" Width="0"
Fill="Maroon" />
<Rectangle Canvas.Top ="-1" Canvas.Left="19" Height="12" Width="202"
StrokeThickness="1" Stroke="Black" />
<TextBlock Name="progressText" Canvas.Top ="-4" Canvas.Left="230"
Text="0%" FontSize="12" />
</Canvas>
<Image Name="loadimg" Height="400" Width="300" />
<Canvas Canvas.Top="70" x:Name="loadxaml"/>